Class ReentryGuard.ReentryGuardImpl
java.lang.Object
ch.qos.logback.core.util.ReentryGuard.ReentryGuardImpl
- All Implemented Interfaces:
ReentryGuard
- Enclosing interface:
ReentryGuard
Default per-thread implementation backed by a
ThreadLocal<Boolean>.
Semantics: a value of Boolean.TRUE indicates the current thread
is inside a guarded region. If the ThreadLocal has no value (null),
isLocked() treats this as unlocked (returns false).
Note: this implementation intentionally uses ThreadLocal<Boolean>
to avoid global synchronization. The initial state is unlocked.
if (!guard.isLocked()) {
guard.lock();
try {
// guarded work
} finally {
guard.unlock();
}
}
- Since:
- 1.5.21
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.qos.logback.core.util.ReentryGuard
ReentryGuard.NOPRentryGuard, ReentryGuard.ReentryGuardImpl -
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
ReentryGuardImpl
public ReentryGuardImpl()
-
-
Method Details
-
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
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
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
-