moved shutdownNow only to the main thread

This commit is contained in:
Rob Austin
2015-02-02 09:11:17 +00:00
parent 4251488b76
commit 4eda29d77e
@@ -55,7 +55,6 @@ abstract class AbstractChannelReplicator implements Closeable {
public static final int SIZE_OF_SIZE = 4;
public static final int SIZE_OF_TRANSACTION_ID = 8;
public static final int SIZE_OF_TIME_SHIFT = 2;
private static final Logger LOG = LoggerFactory.getLogger(AbstractChannelReplicator.class);
@@ -231,7 +230,16 @@ abstract class AbstractChannelReplicator implements Closeable {
if (Thread.interrupted())
LOG.warn("Already interrupted");
long start = System.currentTimeMillis();
closeResources();
try {
closeResources();
if (!executorService.awaitTermination(5, TimeUnit.MILLISECONDS)) {
executorService.shutdownNow();
executorService.awaitTermination(10, TimeUnit.SECONDS);
}
} catch (InterruptedException e) {
LOG.error("", e);
}
try {
if (future != null)
@@ -257,22 +265,11 @@ abstract class AbstractChannelReplicator implements Closeable {
}
}
public void closeResources() {
public void closeResources() throws InterruptedException {
isClosed = true;
executorService.shutdown();
try {
executorService.awaitTermination(5, TimeUnit.MILLISECONDS);
} catch (Exception e) {
executorService.shutdownNow();
try {
executorService.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e1) {
LOG.error("", e);
}
}
closeables.closeQuietly();
if (segmentState != null)
segmentState.close();