Skip to content

Commit 3494a6f

Browse files
committed
fix: thread pool needs to be re-created if we restart after a close call
This is done by moving the close method to static and nulling the singleton so that it can be re-created on next Operator start if needed. This is needed for proper testing support.
1 parent a86dcfa commit 3494a6f

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void start() {
9494
throw new OperatorException(error, e);
9595
}
9696

97-
ExecutorServiceManager.start(configurationService);
97+
ExecutorServiceManager.init(configurationService);
9898
controllers.start();
9999
}
100100

@@ -106,7 +106,7 @@ public void close() {
106106

107107
controllers.close();
108108

109-
ExecutorServiceManager.instance().close();
109+
ExecutorServiceManager.close();
110110
k8sClient.close();
111111
}
112112

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ExecutorServiceManager.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.javaoperatorsdk.operator.api.config;
22

3-
import java.io.Closeable;
43
import java.util.Collection;
54
import java.util.List;
65
import java.util.concurrent.Callable;
@@ -13,7 +12,7 @@
1312
import org.slf4j.Logger;
1413
import org.slf4j.LoggerFactory;
1514

16-
public class ExecutorServiceManager implements Closeable {
15+
public class ExecutorServiceManager {
1716
private static final Logger log = LoggerFactory.getLogger(ExecutorServiceManager.class);
1817
private static ExecutorServiceManager instance;
1918

@@ -25,7 +24,7 @@ private ExecutorServiceManager(ExecutorService executor, int terminationTimeoutS
2524
this.terminationTimeoutSeconds = terminationTimeoutSeconds;
2625
}
2726

28-
public static void start(ConfigurationService configuration) {
27+
public static void init(ConfigurationService configuration) {
2928
if (instance == null) {
3029
instance = new ExecutorServiceManager(
3130
new InstrumentedExecutorService(configuration.getExecutorService()),
@@ -35,6 +34,15 @@ public static void start(ConfigurationService configuration) {
3534
}
3635
}
3736

37+
public static void close() {
38+
if (instance != null) {
39+
instance.stop();
40+
}
41+
// make sure that we remove the singleton so that the thread pool is re-created on next call to
42+
// start
43+
instance = null;
44+
}
45+
3846
public static ExecutorServiceManager instance() {
3947
if (instance == null) {
4048
throw new IllegalStateException(
@@ -47,8 +55,7 @@ public ExecutorService executorService() {
4755
return executor;
4856
}
4957

50-
@Override
51-
public void close() {
58+
private void stop() {
5259
try {
5360
log.debug("Closing executor");
5461
executor.shutdown();

0 commit comments

Comments
 (0)