Skip to content

Commit bd7c6bb

Browse files
committed
a cleaner fix for #088b342
1 parent 088b342 commit bd7c6bb

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/main/java/org/elasticsearch/indices/recovery/RecoverySettings.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.common.unit.ByteSizeValue;
3030
import org.elasticsearch.common.util.concurrent.EsExecutors;
3131
import org.elasticsearch.node.settings.NodeSettingsService;
32+
import org.elasticsearch.threadpool.ThreadPool;
3233

3334
import java.util.concurrent.ThreadPoolExecutor;
3435
import java.util.concurrent.TimeUnit;
@@ -95,14 +96,8 @@ public RecoverySettings(Settings settings, NodeSettingsService nodeSettingsServi
9596
}
9697

9798
public void close() {
98-
concurrentStreamPool.shutdown();
99-
try {
100-
concurrentStreamPool.awaitTermination(1, TimeUnit.SECONDS);
101-
concurrentSmallFileStreamPool.awaitTermination(1, TimeUnit.SECONDS);
102-
} catch (InterruptedException e) {
103-
// that's fine...
104-
}
105-
concurrentStreamPool.shutdownNow();
99+
ThreadPool.terminate(concurrentStreamPool, 1, TimeUnit.SECONDS);
100+
ThreadPool.terminate(concurrentSmallFileStreamPool, 1, TimeUnit.SECONDS);
106101
}
107102

108103
public ByteSizeValue fileChunkSize() {

src/main/java/org/elasticsearch/threadpool/ThreadPool.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,4 +731,23 @@ public void onRefreshSettings(Settings settings) {
731731
updateSettings(settings);
732732
}
733733
}
734+
735+
/**
736+
* Returns <code>true</code> if the given service was terminated successfully. If the termination timed out,
737+
* the service is <code>null</code> this method will return <code>false</code>.
738+
*/
739+
public static boolean terminate(ExecutorService service, long timeout, TimeUnit timeUnit) {
740+
if (service != null) {
741+
service.shutdown();
742+
try {
743+
if (service.awaitTermination(timeout, timeUnit)) {
744+
return true;
745+
}
746+
} catch (InterruptedException e) {
747+
Thread.currentThread().interrupt();
748+
}
749+
service.shutdownNow();
750+
}
751+
return false;
752+
}
734753
}

0 commit comments

Comments
 (0)