|
17 | 17 |
|
18 | 18 | package com.uber.cadence.samples.hello;
|
19 | 19 |
|
| 20 | +import static com.uber.cadence.samples.common.SampleConstants.DOMAIN; |
| 21 | + |
20 | 22 | import com.uber.cadence.activity.ActivityMethod;
|
21 | 23 | import com.uber.cadence.client.WorkflowClient;
|
22 | 24 | import com.uber.cadence.worker.Worker;
|
23 | 25 | import com.uber.cadence.worker.WorkerOptions;
|
24 | 26 | import com.uber.cadence.workflow.Workflow;
|
25 | 27 | import com.uber.cadence.workflow.WorkflowMethod;
|
26 | 28 |
|
27 |
| -import static com.uber.cadence.samples.common.SampleConstants.DOMAIN; |
28 |
| - |
29 | 29 | /**
|
30 |
| - * Hello World Cadence workflow that executes a single activity with full example of how to customize |
31 |
| - * a worker |
| 30 | + * Hello World Cadence workflow that executes a single activity with full example of how to |
| 31 | + * customize a worker |
32 | 32 | */
|
33 | 33 | public class HelloWorkerSetup {
|
34 | 34 |
|
@@ -76,33 +76,38 @@ public static void main(String[] args) {
|
76 | 76 | // Start a worker that hosts both workflow and activity implementations.
|
77 | 77 |
|
78 | 78 | /**
|
79 |
| - * If you see error "Not enough threads to execute workflows" exception it indicates that there are |
80 |
| - * not enough threads to execute currently running workflow tasks. |
81 |
| - * |
82 |
| - * For example, if each workflow uses two threads(using Asycn function) and maxConcurrentWorklfowExecutionSize is 100, |
83 |
| - * and assuming the factory only creates one worker. Then maxWorkflowThreads should be at least 200. |
84 |
| - * With such setup 0 workflows will be cached as all the threads would be consumed by the currently executing workflow tasks. |
85 |
| - * So in general it is better to keep maxWorkflowThreads much higher than maxConcurrentWorklfowExecutionSize to support caching. |
86 |
| - * |
87 |
| - * maxWorkflowThreads defines how many threads all currently executing and cached workflows can use. |
88 |
| - * It's a Factory level option, meaning that the thread pool is shared across all workers created by the factory. |
| 79 | + * If you see error "Not enough threads to execute workflows" exception it indicates that there |
| 80 | + * are not enough threads to execute currently running workflow tasks. |
89 | 81 | *
|
90 |
| - * maxConcurrentWorklfowExecutionSize defines how many workflow tasks can execute in parallel. |
91 |
| - * It's a worker level option. |
| 82 | + * <p>For example, if each workflow uses two threads(using Asycn function) and |
| 83 | + * maxConcurrentWorklfowExecutionSize is 100, and assuming the factory only creates one worker. |
| 84 | + * Then maxWorkflowThreads should be at least 200. With such setup 0 workflows will be cached as |
| 85 | + * all the threads would be consumed by the currently executing workflow tasks. So in general it |
| 86 | + * is better to keep maxWorkflowThreads much higher than maxConcurrentWorklfowExecutionSize to |
| 87 | + * support caching. |
92 | 88 | *
|
| 89 | + * <p>maxWorkflowThreads defines how many threads all currently executing and cached workflows |
| 90 | + * can use. It's a Factory level option, meaning that the thread pool is shared across all |
| 91 | + * workers created by the factory. |
93 | 92 | *
|
| 93 | + * <p>maxConcurrentWorklfowExecutionSize defines how many workflow tasks can execute in |
| 94 | + * parallel. It's a worker level option. |
94 | 95 | */
|
95 |
| - Worker.Factory factory = new Worker.Factory(DOMAIN, |
| 96 | + Worker.Factory factory = |
| 97 | + new Worker.Factory( |
| 98 | + DOMAIN, |
96 | 99 | new Worker.FactoryOptions.Builder()
|
97 |
| - .setMaxWorkflowThreadCount(1000) |
98 |
| - .setCacheMaximumSize(100) |
99 |
| - .setDisableStickyExecution(false) |
100 |
| - .build()); |
101 |
| - Worker worker = factory.newWorker(TASK_LIST, |
| 100 | + .setMaxWorkflowThreadCount(1000) |
| 101 | + .setCacheMaximumSize(100) |
| 102 | + .setDisableStickyExecution(false) |
| 103 | + .build()); |
| 104 | + Worker worker = |
| 105 | + factory.newWorker( |
| 106 | + TASK_LIST, |
102 | 107 | new WorkerOptions.Builder()
|
103 |
| - .setMaxConcurrentActivityExecutionSize(100) |
104 |
| - .setMaxConcurrentWorkflowExecutionSize(100) |
105 |
| - .build()); |
| 108 | + .setMaxConcurrentActivityExecutionSize(100) |
| 109 | + .setMaxConcurrentWorkflowExecutionSize(100) |
| 110 | + .build()); |
106 | 111 | // Workflows are stateful. So you need a type to create instances.
|
107 | 112 | worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class);
|
108 | 113 | // Activities are stateless and thread safe. So a shared instance is used.
|
|
0 commit comments