Interface ReentryGuard
- All Known Implementing Classes:
ReentryGuard.NOPRentryGuard,ReentryGuard.ReentryGuardImpl
Implementations are used by appenders and other components that must avoid
recursively calling back into themselves (for example when an error causes
logging while handling a logging event). Typical usage: check isLocked()
before proceeding and call lock() / unlock() around the
guarded region.
Concurrency: guards operate on a per-thread basis; callers should treat the
guard as thread-local state. Implementations must document their semantics;
the provided ReentryGuard.ReentryGuardImpl uses a ThreadLocal to track the
locked state for the current thread.
- Since:
- 1.5.21
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classNo-op implementation that never locks.static classDefault per-thread implementation backed by aThreadLocal<Boolean>. -
Method Summary
-
Method Details
-
isLocked
boolean isLocked()Return 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 calledlock()or if the stored value isnull.- Returns:
trueif the guard is locked for the current thread,falseotherwise
-
lock
-
unlock
void unlock()Release the guard for the current thread.After calling
unlock()theisLocked()should returnfalsefor the current thread (unlesslock()is called again).
-