From 21b0d96493703621c025f1309cbf4fe55115a720 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Tue, 25 Nov 2014 15:17:53 +0000 Subject: [PATCH] HCOLL-216 added better close support for the executor --- .../chronicle/map/StatelessChronicleMap.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java index 759359e61..c487150ba 100644 --- a/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java +++ b/src/main/java/net/openhft/chronicle/map/StatelessChronicleMap.java @@ -38,10 +38,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.SocketChannel; import java.util.*; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; +import java.util.concurrent.*; import static java.nio.ByteBuffer.allocateDirect; import static net.openhft.chronicle.map.AbstractChannelReplicator.SIZE_OF_SIZE; @@ -309,6 +306,19 @@ class StatelessChronicleMap implements ChronicleMap, Closeable, Clon if (closeables != null) closeables.closeQuietly(); closeables = null; + + if (executorService != null) { + executorService.shutdown(); + try { + if (!executorService.awaitTermination(20, TimeUnit.SECONDS)) { + executorService.shutdownNow(); + } + } catch (InterruptedException e) { + LOG.error("", e); + } + } + + try { Thread.sleep(100); } catch (InterruptedException e) {