From ec919b94eb9764b32c0db6293b7788b178057421 Mon Sep 17 00:00:00 2001 From: leventov Date: Sat, 1 Oct 2016 17:08:26 +0300 Subject: [PATCH] More clarifying comments in ThreadLocalState.closeContext() --- .../chronicle/hash/impl/stage/hash/ThreadLocalState.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/net/openhft/chronicle/hash/impl/stage/hash/ThreadLocalState.java b/src/main/java/net/openhft/chronicle/hash/impl/stage/hash/ThreadLocalState.java index 4941373a3..c728e8b49 100644 --- a/src/main/java/net/openhft/chronicle/hash/impl/stage/hash/ThreadLocalState.java +++ b/src/main/java/net/openhft/chronicle/hash/impl/stage/hash/ThreadLocalState.java @@ -84,9 +84,15 @@ public abstract class ThreadLocalState { public void closeContext() { if (tryCloseContext()) return; + // If first attempt of closing a context (i. e. moving from unused to closed state) failed, + // it means that the context is still in use. If this context belongs to the current thread, + // this is a bug, because we cannot "wait" until context is unused in the same thread: if (owner() == Thread.currentThread()) throw new IllegalStateException("Attempt to close a Chronicle Hash in the context " + "of not yet finished query or iteration"); + // If the context belongs to a different thread, wait until that thread finishes it's work + // with the context: + // Double the current timeout for segment locks "without timeout", that effectively // specifies maximum lock (hence context) holding time long timeoutMillis = TimeUnit.SECONDS.toMillis(LOCK_TIMEOUT_SECONDS) * 2;