Interface ReentryGuard

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 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 Classes
    Modifier and Type
    Interface
    Description
    static class 
    No-op implementation that never locks.
    static class 
    Default per-thread implementation backed by a ThreadLocal<Boolean>.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Return true if the current thread holds the guard (i.e.
    void
    Mark the guard as locked for the current thread.
    void
    Release the guard for the current thread.
  • Method Details

    • isLocked

      boolean isLocked()
      Return true if the current thread holds the guard (i.e. is inside a guarded region).

      Implementations typically return false if the current thread has not previously called lock() or if the stored value is null.

      Returns:
      true if the guard is locked for the current thread, false otherwise
    • 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() the isLocked() should return false for the current thread (unless lock() is called again).