Skip to content

Commit e698c3a

Browse files
authored
Merge pull request #2020 from jponge/feat/infra-executor-shutdown
feat: flag to control the Infrastructure executor shutdown on update
2 parents 8b8d066 + 9690251 commit e698c3a

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

implementation/src/main/java/io/smallrye/mutiny/infrastructure/Infrastructure.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,37 @@ public static void setDefaultExecutor() {
8787
setDefaultExecutor(scheduler);
8888
}
8989

90+
/**
91+
* Changes the default executor, and shuts the previous executor down.
92+
*
93+
* @param s the new executor
94+
*/
9095
public static void setDefaultExecutor(Executor s) {
91-
if (s == DEFAULT_EXECUTOR) {
96+
setDefaultExecutor(s, true);
97+
}
98+
99+
/**
100+
* Changes the default executor, and shuts the previous executor down when {@code shutdownPrevious} is {@code true}.
101+
*
102+
* @param executor the new executor
103+
* @param shutdownPrevious {@code true} when the previous executor needs to be shut down, {@code false} otherwise
104+
*/
105+
public static void setDefaultExecutor(Executor executor, boolean shutdownPrevious) {
106+
if (executor == DEFAULT_EXECUTOR) {
92107
return;
93108
}
94-
Executor existing = DEFAULT_EXECUTOR;
95-
if (existing instanceof ExecutorService) {
96-
((ExecutorService) existing).shutdownNow();
97-
}
98-
if (DEFAULT_SCHEDULER != null) {
99-
DEFAULT_SCHEDULER.shutdownNow();
109+
if (shutdownPrevious) {
110+
Executor existing = DEFAULT_EXECUTOR;
111+
if (existing instanceof ExecutorService) {
112+
((ExecutorService) existing).shutdownNow();
113+
}
114+
if (DEFAULT_SCHEDULER != null) {
115+
DEFAULT_SCHEDULER.shutdownNow();
116+
}
100117
}
101-
DEFAULT_EXECUTOR = s;
102-
DEFAULT_SCHEDULER = (s instanceof ScheduledExecutorService) ? (ScheduledExecutorService) s : new MutinyScheduler(s);
118+
DEFAULT_EXECUTOR = executor;
119+
DEFAULT_SCHEDULER = (executor instanceof ScheduledExecutorService) ? (ScheduledExecutorService) executor
120+
: new MutinyScheduler(executor);
103121
}
104122

105123
public static ScheduledExecutorService getDefaultWorkerPool() {

0 commit comments

Comments
 (0)