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 {
3030 logger .info (
3131 "Workflow output is {}" ,
3232 appl .workflowDefinition (WorkflowReader .readWorkflowFromClasspath ("get.yaml" ))
33- .instance (Map .of ("petId" , 10 ))
33+ .instance (Map .of ("petId" , 1 ))
3434 .start ()
3535 .join ());
3636 }
Original file line number Diff line number Diff line change 2121public class DefaultExecutorServiceFactory implements ExecutorServiceFactory {
2222
2323 private static final ExecutorServiceFactory instance = new DefaultExecutorServiceFactory ();
24+ private static boolean serviceLoaded ;
2425
2526 public static ExecutorServiceFactory instance () {
2627 return instance ;
2728 }
2829
2930 private static class ExecutorServiceHolder {
31+ static {
32+ serviceLoaded = true ;
33+ }
34+
3035 private static ExecutorService instance = Executors .newCachedThreadPool ();
3136 }
3237
@@ -36,4 +41,11 @@ public ExecutorService get() {
3641 }
3742
3843 private DefaultExecutorServiceFactory () {}
44+
45+ @ Override
46+ public void close () {
47+ if (serviceLoaded ) {
48+ ExecutorServiceHolder .instance .shutdownNow ();
49+ }
50+ }
3951}
Original file line number Diff line number Diff line change 1818import java .util .concurrent .ExecutorService ;
1919import java .util .function .Supplier ;
2020
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 3939import java .util .ServiceLoader .Provider ;
4040import java .util .concurrent .ConcurrentHashMap ;
4141import java .util .concurrent .ExecutorService ;
42- import java .util .concurrent .Executors ;
4342import java .util .stream .Collectors ;
4443
4544public class WorkflowApplication implements AutoCloseable {
@@ -137,7 +136,7 @@ public SchemaValidator getValidator(SchemaInline inline) {
137136 private SchemaValidatorFactory schemaValidatorFactory ;
138137 private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition ();
139138 private WorkflowIdFactory idFactory = () -> UlidCreator .getMonotonicUlid ().toString ();
140- private ExecutorServiceFactory executorFactory = () -> Executors . newCachedThreadPool ();
139+ private ExecutorServiceFactory executorFactory = DefaultExecutorServiceFactory . instance ();
141140 private EventConsumer <?, ?> eventConsumer = InMemoryEvents .get ();
142141 private EventPublisher eventPublisher = InMemoryEvents .get ();
143142 private RuntimeDescriptorFactory descriptorFactory =
@@ -236,6 +235,7 @@ public WorkflowDefinition workflowDefinition(Workflow workflow) {
236235
237236 @ Override
238237 public void close () {
238+ executorFactory .close ();
239239 for (WorkflowDefinition definition : definitions .values ()) {
240240 definition .close ();
241241 }
You can’t perform that action at this time.
0 commit comments