- java.lang.Object
-
- ch.qos.logback.core.util.ReentryGuard.ReentryGuardImpl
-
- All Implemented Interfaces:
ReentryGuard
- Enclosing interface:
- ReentryGuard
public static class ReentryGuard.ReentryGuardImpl extends Object implements ReentryGuard
Default per-thread implementation backed by aThreadLocal.Semantics: a value of
Boolean.TRUEindicates the current thread is inside a guarded region. If the ThreadLocal has no value (null),isLocked()treats this as unlocked (returnsfalse).Note: this implementation intentionally uses
Typical usage:ThreadLocal<Boolean>to avoid global synchronization. The initial state is unlocked.if (!guard.isLocked()) { guard.lock(); try { // guarded work } finally { guard.unlock(); } }
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ch.qos.logback.core.util.ReentryGuard
ReentryGuard.NOPRentryGuard, ReentryGuard.ReentryGuardImpl
-
-
Constructor Summary
Constructors Constructor Description ReentryGuardImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisLocked()Return true if the current thread holds the guard (i.e. is inside a guarded region).voidlock()Mark the guard as locked for the current thread.voidunlock()Release the guard for the current thread.
-
-
-
Constructor Detail
-
ReentryGuardImpl
public ReentryGuardImpl()
-
-
Method Detail
-
isLocked
public boolean isLocked()
Description copied from interface:ReentryGuardReturn true if the current thread holds the guard (i.e. is inside a guarded region).Implementations typically return
falseif the current thread has not previously calledReentryGuard.lock()or if the stored value isnull.- Specified by:
isLockedin interfaceReentryGuard- Returns:
trueif the guard is locked for the current thread,falseotherwise
-
lock
public void lock()
Description copied from interface:ReentryGuardMark the guard as locked for the current thread.Callers must ensure
ReentryGuard.unlock()is invoked in a finally block to avoid leaving the guard permanently locked for the thread.- Specified by:
lockin interfaceReentryGuard
-
unlock
public void unlock()
Description copied from interface:ReentryGuardRelease the guard for the current thread.After calling
unlock()theReentryGuard.isLocked()should returnfalsefor the current thread (unlesslock()is called again).- Specified by:
unlockin interfaceReentryGuard
-
-