Make OldDeletedCleanupThread daemon and don't wait for this thread to cease in ReplicatedChronicleMap.close(), because if the thread is already dead by the time cleanupThread.join() is called, this call hangs

This commit is contained in:
leventov
2016-12-26 14:27:32 +08:00
parent dad7313bf4
commit 4bb2decc34
2 changed files with 1 additions and 13 deletions
@@ -1811,19 +1811,6 @@ public final class ChronicleMapBuilder<K, V> implements
OldDeletedEntriesCleanupThread cleanupThread = new OldDeletedEntriesCleanupThread(map);
map.addCloseable(cleanupThread);
cleanupThread.start();
// WARNING this relies on the fact that ReplicatedChronicleMap closes closeables in the same
// order as they are added, i. e. OldDeletedEntriesCleanupThread instance close()d before
// the following closeable
String mapIdentityString = map.toIdentityString();
map.addCloseable(() -> {
try {
cleanupThread.join();
} catch (InterruptedException e) {
LOG.warn(mapIdentityString +
": Interrupted while waiting for the cleanup thread to cease");
Thread.currentThread().interrupt();
}
});
}
/**
@@ -76,6 +76,7 @@ class OldDeletedEntriesCleanupThread extends Thread
OldDeletedEntriesCleanupThread(ReplicatedChronicleMap<?, ?, ?> map) {
super("Cleanup Thread for " + map.toIdentityString());
setDaemon(true);
this.mapRef = new WeakReference<>(map);
cleanupTimeout = map.cleanupTimeout;
cleanupTimeoutUnit = map.cleanupTimeoutUnit;