diff --git a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java index 9d37dfa06..684dff7d3 100644 --- a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java +++ b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java @@ -501,8 +501,6 @@ final class ChannelProvider implements Closeable { @Override public void close() throws IOException { - // synchronized on parent instance to prevent possible (but very unlikely) contention - // between close() calls on different channels channelDataLock.writeLock().lock(); try { chronicleChannelList.remove(chronicleChannels[chronicleChannel]); diff --git a/src/main/java/net/openhft/chronicle/map/InstanceConfig.java b/src/main/java/net/openhft/chronicle/map/InstanceConfig.java index e73d2778a..5e75a6492 100644 --- a/src/main/java/net/openhft/chronicle/map/InstanceConfig.java +++ b/src/main/java/net/openhft/chronicle/map/InstanceConfig.java @@ -32,6 +32,8 @@ final class InstanceConfig final ReplicationChannel channel; final File file; + private boolean used = false; + InstanceConfig(AbstractChronicleMapBuilder mapBuilder, SingleChronicleHashReplication singleHashReplication, ReplicationChannel channel, @@ -67,7 +69,15 @@ final class InstanceConfig } @Override - public ChronicleMap create() throws IOException { + public synchronized ChronicleMap create() throws IOException { + if (used) + throw new IllegalStateException( + "A ChronicleMap has already been created using this instance config. " + + "Create a new instance config (builder.instance() or call any " + + "configuration method on this instance config) to create a new " + + "ChronicleMap instance"); + used = true; return mapBuilder.create(this); } + } diff --git a/src/main/java/net/openhft/chronicle/set/InstanceConfig.java b/src/main/java/net/openhft/chronicle/set/InstanceConfig.java index e7fe620c4..9d3f43f6c 100644 --- a/src/main/java/net/openhft/chronicle/set/InstanceConfig.java +++ b/src/main/java/net/openhft/chronicle/set/InstanceConfig.java @@ -29,6 +29,8 @@ final class InstanceConfig implements ChronicleHashInstanceConfig> mapConfig; + private boolean used; + InstanceConfig(ChronicleHashInstanceConfig> mapConfig) { this.mapConfig = mapConfig; } @@ -56,7 +58,14 @@ final class InstanceConfig implements ChronicleHashInstanceConfig create() throws IOException { + public synchronized ChronicleSet create() throws IOException { + if (used) + throw new IllegalStateException( + "A ChronicleSet has already been created using this instance config. " + + "Create a new instance config (builder.instance() or call any " + + "configuration method on this instance config) to create a new " + + "ChronicleSet instance"); + used = true; return new SetFromMap<>(mapConfig.create()); } }