-
- All Known Implementing Classes:
ReentryGuard.NOPRentryGuard,ReentryGuard.ReentryGuardImpl
public interface ReentryGuard
Guard used to prevent re-entrant (recursive) appender invocations on a per-thread basis.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 calllock()/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.ReentryGuardImpluses aThreadLocalto track the locked state for the current thread.- Since:
- 1.5.21
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classReentryGuard.NOPRentryGuardNo-op implementation that never locks.static classReentryGuard.ReentryGuardImplDefault per-thread implementation backed by aThreadLocal.
-
Method Summary
All Methods Instance Methods Abstract 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.
-
-
-
Method Detail
-
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
void lock()
Mark the guard as locked for the current thread.Callers must ensure
unlock()is invoked in a finally block to avoid leaving the guard permanently locked for the thread.
-
unlock
void unlock()
Release the guard for the current thread.After calling
unlock()theisLocked()should returnfalsefor the current thread (unlesslock()is called again).
-
-