Expose prestartAllCoreThreads on ExecutorService

See gh-1246
This commit is contained in:
Federico Donnarumma
2016-11-25 17:33:49 -03:00
committed by Stephane Nicoll
parent 2271b6078e
commit 2c53e9e308
2 changed files with 83 additions and 2 deletions

View File

@@ -73,12 +73,14 @@ public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport
private int keepAliveSeconds = 60;
private boolean allowCoreThreadTimeOut = false;
private int queueCapacity = Integer.MAX_VALUE;
private boolean allowCoreThreadTimeOut = false;
private boolean exposeUnconfigurableExecutor = false;
private boolean prestartAllCoreThreads = false;
@Nullable
private ExecutorService exposedExecutor;
@@ -130,6 +132,17 @@ public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport
this.queueCapacity = queueCapacity;
}
/**
* Specify whether this FactoryBean should prestart all threads
* for the created executor.
* <p>Default is "false".
* Switch this flag to "true" to prestart the threads allocated for the current executor
* @see java.util.concurrent.ThreadPoolExecutor#prestartAllCoreThreads
*/
public void setPrestartAllCoreThreads(boolean prestartAllCoreThreads) {
this.prestartAllCoreThreads = prestartAllCoreThreads;
}
/**
* Specify whether this FactoryBean should expose an unconfigurable
* decorator for the created executor.
@@ -154,6 +167,10 @@ public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport
executor.allowCoreThreadTimeOut(true);
}
if (this.prestartAllCoreThreads) {
executor.prestartAllCoreThreads();
}
// Wrap executor with an unconfigurable decorator.
this.exposedExecutor = (this.exposeUnconfigurableExecutor ?
Executors.unconfigurableExecutorService(executor) : executor);