Skip to content

Commit c66b995

Browse files
fix: make executor threads deamon (#601)
* make executor threads deamon Signed-off-by: Kavindu Dodanduwa <[email protected]> * unify annotation usage Signed-off-by: Kavindu Dodanduwa <[email protected]> --------- Signed-off-by: Kavindu Dodanduwa <[email protected]>
1 parent 4c686c9 commit c66b995

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package dev.openfeature.sdk;
22

3+
import lombok.extern.slf4j.Slf4j;
4+
5+
import javax.annotation.Nullable;
36
import java.util.ArrayList;
47
import java.util.List;
58
import java.util.Map;
@@ -11,9 +14,6 @@
1114
import java.util.concurrent.Executors;
1215
import java.util.function.Consumer;
1316

14-
import edu.umd.cs.findbugs.annotations.Nullable;
15-
import lombok.extern.slf4j.Slf4j;
16-
1717
/**
1818
* Util class for storing and running handlers.
1919
*/
@@ -23,9 +23,13 @@ class EventSupport {
2323
// we use a v4 uuid as a "placeholder" for anonymous clients, since
2424
// ConcurrentHashMap doesn't support nulls
2525
private static final String defaultClientUuid = UUID.randomUUID().toString();
26-
private final ExecutorService taskExecutor = Executors.newCachedThreadPool();
2726
private final Map<String, HandlerStore> handlerStores = new ConcurrentHashMap<>();
2827
private final HandlerStore globalHandlerStore = new HandlerStore();
28+
private final ExecutorService taskExecutor = Executors.newCachedThreadPool(runnable -> {
29+
final Thread thread = new Thread(runnable);
30+
thread.setDaemon(true);
31+
return thread;
32+
});
2933

3034
/**
3135
* Run all the event handlers associated with this client name.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ class ProviderRepository {
2222

2323
private final Map<String, FeatureProvider> providers = new ConcurrentHashMap<>();
2424
private final AtomicReference<FeatureProvider> defaultProvider = new AtomicReference<>(new NoOpProvider());
25-
private final ExecutorService taskExecutor = Executors.newCachedThreadPool();
25+
private final ExecutorService taskExecutor = Executors.newCachedThreadPool(runnable -> {
26+
final Thread thread = new Thread(runnable);
27+
thread.setDaemon(true);
28+
return thread;
29+
});
2630

2731
/**
2832
* Return the default provider.

0 commit comments

Comments
 (0)