Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class DefaultExecutorServiceFactory implements ExecutorServiceFactory {
private ExecutorService service = Executors.newCachedThreadPool();
Expand All @@ -29,9 +28,6 @@ public ExecutorService get() {

@Override
public void close() throws Exception {
if (!service.isShutdown()) {
service.shutdown();
service.awaitTermination(2, TimeUnit.SECONDS);
}
WorkflowUtils.safeShutdown(service);
Comment thread
fjtirado marked this conversation as resolved.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static io.serverlessworkflow.impl.WorkflowUtils.loadFirst;
import static io.serverlessworkflow.impl.WorkflowUtils.safeClose;
import static io.serverlessworkflow.impl.WorkflowUtils.safeShutdown;

import io.serverlessworkflow.api.types.SchemaInline;
import io.serverlessworkflow.api.types.Workflow;
Expand Down Expand Up @@ -585,11 +586,11 @@ public WorkflowDefinition workflowDefinition(Workflow workflow) {
@Override
public void close() {
safeClose(executorFactory);
safeShutdown(schedulerExecutorService);
for (EventPublisher eventPublisher : eventPublishers) {
safeClose(eventPublisher);
}
safeClose(eventConsumer);

for (WorkflowDefinition definition : definitions.values()) {
safeClose(definition);
}
Expand All @@ -604,9 +605,6 @@ public void close() {
}
listenersByPriority.clear();
}
if (this.schedulerExecutorService != null) {
schedulerExecutorService.shutdownNow();
}
}

public WorkflowPositionFactory positionFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import java.util.Objects;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -177,6 +179,18 @@ public static void safeClose(AutoCloseable closeable) {
}
}

public static void safeShutdown(ExecutorService service) {
if (service != null && !service.isShutdown()) {
try {
service.shutdownNow();
service.awaitTermination(2, TimeUnit.SECONDS);
Comment thread
fjtirado marked this conversation as resolved.
Comment thread
fjtirado marked this conversation as resolved.
} catch (InterruptedException ex) {
logger.warn("Thread was interrupted when awaiting service task termination", ex);
Thread.currentThread().interrupt();
}
}
}

public static boolean whenExceptTest(
Optional<WorkflowPredicate> whenFilter,
Optional<WorkflowPredicate> exceptFilter,
Expand Down
Loading