Class ReentryGuard.NOPRentryGuard

  • All Implemented Interfaces:
    ReentryGuard
    Enclosing interface:
    ReentryGuard

    public static class ReentryGuard.NOPRentryGuard
    extends Object
    implements ReentryGuard
    No-op implementation that never locks. Useful in contexts where re-entrancy protection is not required.

    isLocked() always returns false. lock() and unlock() are no-ops.

    Use this implementation when the caller explicitly wants to disable reentrancy protection (for example in tests or in environments where the cost of thread-local checks is undesirable and re-entrancy cannot occur).

    • Method Detail

      • isLocked

        public boolean isLocked()
        Description copied from interface: ReentryGuard
        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 ReentryGuard.lock() or if the stored value is null.

        Specified by:
        isLocked in interface ReentryGuard
        Returns:
        true if the guard is locked for the current thread, false otherwise
      • lock

        public void lock()
        Description copied from interface: ReentryGuard
        Mark 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:
        lock in interface ReentryGuard
      • unlock

        public void unlock()
        Description copied from interface: ReentryGuard
        Release the guard for the current thread.

        After calling unlock() the ReentryGuard.isLocked() should return false for the current thread (unless lock() is called again).

        Specified by:
        unlock in interface ReentryGuard