[Fix] ExecutorPool should use different pools for scheduledExecutors and ExecutorService
This commit is contained in:
parent
006a08a3d2
commit
d5fd5018cd
|
@ -18,9 +18,11 @@ public class ExecutorPool {
|
|||
private static final Logger logger = LoggerFactory.getLogger(ExecutorPool.class);
|
||||
|
||||
private Map<String, ExecutorService> executors;
|
||||
private Map<String, ScheduledExecutorService> scheduledExecutors;
|
||||
|
||||
public ExecutorPool() {
|
||||
this.executors = Collections.synchronizedMap(new HashMap<>());
|
||||
this.scheduledExecutors = Collections.synchronizedMap(new HashMap<>());
|
||||
}
|
||||
|
||||
public ExecutorService getExecutor(String poolName) {
|
||||
|
@ -35,7 +37,7 @@ public class ExecutorPool {
|
|||
|
||||
public ScheduledExecutorService getScheduledExecutor(String poolName) {
|
||||
DBC.PRE.assertNotEmpty("poolName must be set!", poolName);
|
||||
return (ScheduledExecutorService) this.executors
|
||||
return this.scheduledExecutors
|
||||
.computeIfAbsent(poolName, p -> newScheduledThreadPool(4, new NamedThreadPoolFactory(p)));
|
||||
}
|
||||
|
||||
|
@ -45,6 +47,17 @@ public class ExecutorPool {
|
|||
logger.info("Shutting down executor pool " + poolName);
|
||||
ExecutorService executor = this.executors.get(poolName);
|
||||
|
||||
shutdownExecutor(executor);
|
||||
}
|
||||
for (String poolName : this.scheduledExecutors.keySet()) {
|
||||
logger.info("Shutting down scheduled executor pool " + poolName);
|
||||
ExecutorService executor = this.scheduledExecutors.get(poolName);
|
||||
|
||||
shutdownExecutor(executor);
|
||||
}
|
||||
}
|
||||
|
||||
private void shutdownExecutor(ExecutorService executor) {
|
||||
try {
|
||||
executor.shutdown();
|
||||
executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||
|
@ -58,4 +71,3 @@ public class ExecutorPool {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue