Only rethrow exceptions if they are coming from the actual runnable but not if we are shutting down the pool

This commit is contained in:
Simon Willnauer 2016-01-27 21:06:24 +01:00
parent 5b836dbb11
commit 7ef762c8f0
2 changed files with 9 additions and 7 deletions

View File

@ -184,13 +184,14 @@ public class EsThreadPoolExecutor extends ThreadPoolExecutor {
@Override
protected void doRun() throws Exception {
boolean started = false;
boolean whileRunning = false;
try (ThreadContext.StoredContext ingore = contextHolder.stashContext()){
ctx.restore();
started = true;
whileRunning = true;
in.doRun();
whileRunning = false;
} catch (IllegalStateException ex) {
if (started || isShutdown() == false) {
if (whileRunning || isShutdown() == false) {
throw ex;
}
// if we hit an ISE here we have been shutting down
@ -219,13 +220,14 @@ public class EsThreadPoolExecutor extends ThreadPoolExecutor {
@Override
public void run() {
boolean started = false;
boolean whileRunning = false;
try (ThreadContext.StoredContext ingore = contextHolder.stashContext()){
ctx.restore();
started = true;
whileRunning = true;
in.run();
whileRunning = false;
} catch (IllegalStateException ex) {
if (started || isShutdown() == false) {
if (whileRunning || isShutdown() == false) {
throw ex;
}
// if we hit an ISE here we have been shutting down

View File

@ -325,7 +325,7 @@ public class UpdateThreadPoolSettingsTests extends ESTestCase {
try {
Settings nodeSettings = Settings.settingsBuilder()
.put("threadpool." + threadPoolName + ".queue_size", 1000)
.put("name", "testCachedExecutorType").build();
.put("name", "testShutdownNowInterrupts").build();
threadPool = new ThreadPool(nodeSettings);
ClusterSettings clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
threadPool.setClusterSettings(clusterSettings);