File tree Expand file tree Collapse file tree 4 files changed +18
-5
lines changed
examples/simpleGet/src/main/java/io/serverlessworkflow/impl
impl/core/src/main/java/io/serverlessworkflow/impl Expand file tree Collapse file tree 4 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ public static void main(String[] args) throws IOException {
30
30
logger .info (
31
31
"Workflow output is {}" ,
32
32
appl .workflowDefinition (WorkflowReader .readWorkflowFromClasspath ("get.yaml" ))
33
- .instance (Map .of ("petId" , 10 ))
33
+ .instance (Map .of ("petId" , 1 ))
34
34
.start ()
35
35
.join ());
36
36
}
Original file line number Diff line number Diff line change 21
21
public class DefaultExecutorServiceFactory implements ExecutorServiceFactory {
22
22
23
23
private static final ExecutorServiceFactory instance = new DefaultExecutorServiceFactory ();
24
+ private static boolean serviceLoaded ;
24
25
25
26
public static ExecutorServiceFactory instance () {
26
27
return instance ;
27
28
}
28
29
29
30
private static class ExecutorServiceHolder {
31
+ static {
32
+ serviceLoaded = true ;
33
+ }
34
+
30
35
private static ExecutorService instance = Executors .newCachedThreadPool ();
31
36
}
32
37
@@ -36,4 +41,11 @@ public ExecutorService get() {
36
41
}
37
42
38
43
private DefaultExecutorServiceFactory () {}
44
+
45
+ @ Override
46
+ public void close () {
47
+ if (serviceLoaded ) {
48
+ ExecutorServiceHolder .instance .shutdownNow ();
49
+ }
50
+ }
39
51
}
Original file line number Diff line number Diff line change 18
18
import java .util .concurrent .ExecutorService ;
19
19
import java .util .function .Supplier ;
20
20
21
- @ FunctionalInterface
22
- public interface ExecutorServiceFactory extends Supplier <ExecutorService > {}
21
+ public interface ExecutorServiceFactory extends Supplier <ExecutorService >, AutoCloseable {
22
+ void close ();
23
+ }
Original file line number Diff line number Diff line change 39
39
import java .util .ServiceLoader .Provider ;
40
40
import java .util .concurrent .ConcurrentHashMap ;
41
41
import java .util .concurrent .ExecutorService ;
42
- import java .util .concurrent .Executors ;
43
42
import java .util .stream .Collectors ;
44
43
45
44
public class WorkflowApplication implements AutoCloseable {
@@ -137,7 +136,7 @@ public SchemaValidator getValidator(SchemaInline inline) {
137
136
private SchemaValidatorFactory schemaValidatorFactory ;
138
137
private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition ();
139
138
private WorkflowIdFactory idFactory = () -> UlidCreator .getMonotonicUlid ().toString ();
140
- private ExecutorServiceFactory executorFactory = () -> Executors . newCachedThreadPool ();
139
+ private ExecutorServiceFactory executorFactory = DefaultExecutorServiceFactory . instance ();
141
140
private EventConsumer <?, ?> eventConsumer = InMemoryEvents .get ();
142
141
private EventPublisher eventPublisher = InMemoryEvents .get ();
143
142
private RuntimeDescriptorFactory descriptorFactory =
@@ -236,6 +235,7 @@ public WorkflowDefinition workflowDefinition(Workflow workflow) {
236
235
237
236
@ Override
238
237
public void close () {
238
+ executorFactory .close ();
239
239
for (WorkflowDefinition definition : definitions .values ()) {
240
240
definition .close ();
241
241
}
You can’t perform that action at this time.
0 commit comments