Skip to content

Commit a483239

Browse files
jarebudevKavindu-Dodan
authored andcommitted
shutdown method blocks until task executor shutdown completes
Signed-off-by: jarebudev <[email protected]>
1 parent f97cdd7 commit a483239

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/java/dev/openfeature/sdk/EventSupport.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.concurrent.ConcurrentHashMap;
1313
import java.util.concurrent.ExecutorService;
1414
import java.util.concurrent.Executors;
15+
import java.util.concurrent.TimeUnit;
1516
import java.util.function.Consumer;
1617

1718
/**
@@ -23,6 +24,7 @@ class EventSupport {
2324
// we use a v4 uuid as a "placeholder" for anonymous clients, since
2425
// ConcurrentHashMap doesn't support nulls
2526
private static final String defaultClientUuid = UUID.randomUUID().toString();
27+
private static final int SHUTDOWN_TIMEOUT_SECONDS = 3;
2628
private final Map<String, HandlerStore> handlerStores = new ConcurrentHashMap<>();
2729
private final HandlerStore globalHandlerStore = new HandlerStore();
2830
private final ExecutorService taskExecutor = Executors.newCachedThreadPool(runnable -> {
@@ -146,11 +148,15 @@ public void runHandler(Consumer<EventDetails> handler, EventDetails eventDetails
146148
}
147149

148150
/**
149-
* Stop the event handler task executor.
151+
* Stop the event handler task executor and block until either termination has completed
152+
* or timeout period has elapsed.
150153
*/
151154
public void shutdown() {
152155
try {
153156
taskExecutor.shutdown();
157+
if (!taskExecutor.awaitTermination(SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
158+
log.warn("Task executor did not terminate before the timeout period had elapsed");
159+
}
154160
} catch (Exception e) {
155161
log.warn("Exception while attempting to shutdown task executor", e);
156162
}

0 commit comments

Comments
 (0)