Try to close alive ChronicleMaps on JVM shutdown

This commit is contained in:
leventov
2016-10-02 18:42:39 +03:00
parent 4b1f11dd3a
commit a2c8ac4866
4 changed files with 101 additions and 8 deletions
@@ -1504,14 +1504,19 @@ public final class ChronicleMapBuilder<K, V> implements
} finally {
if (result != null) {
result.registerRafReleaser();
// Ensure safe publication of a ChronicleMap
OS.memory().storeFence();
prepareMapPublication(result);
} else {
CanonicalRandomAccessFiles.release(file);
}
}
}
private static void prepareMapPublication(VanillaChronicleMap map) {
// Ensure safe publication of a ChronicleMap
OS.memory().storeFence();
ChronicleMapCloseOnExitHook.add(map);
}
/**
* @return size of the self bootstrapping header
*/
@@ -1669,8 +1674,7 @@ public final class ChronicleMapBuilder<K, V> implements
lazyNativeBytesStoreWithFixedCapacity(map.sizeInBytesWithoutTiers());
map.createMappedStoreAndSegments(bytesStore);
establishReplication(map);
// Ensure "safe publication" of a ChronicleMap
OS.memory().storeFence();
prepareMapPublication(map);
return map;
} catch (IOException e) {
// file-less version should never trigger an IOException.