Class NoOpLock

java.lang.Object
org.agrona.concurrent.NoOpLock
All Implemented Interfaces:
Lock

public final class NoOpLock extends Object implements Lock
A Lock implementation that is a no operation, i.e. it effectively does nothing.

Useful for effectively eliding a lock in a single threaded environment.

  • Field Details

    • INSTANCE

      public static final NoOpLock INSTANCE
      As there is no instance state then this object can be used to save on allocation.
  • Constructor Details

    • NoOpLock

      public NoOpLock()
  • Method Details

    • lock

      public void lock()
      Proceeds as if the lock has been acquired.
      Specified by:
      lock in interface Lock
    • lockInterruptibly

      public void lockInterruptibly()
      Proceeds as if the lock has been acquired.
      Specified by:
      lockInterruptibly in interface Lock
    • tryLock

      public boolean tryLock()
      Always succeeds.
      Specified by:
      tryLock in interface Lock
      Returns:
      always true.
    • tryLock

      public boolean tryLock(long time, TimeUnit unit)
      Always succeeds.
      Specified by:
      tryLock in interface Lock
      Parameters:
      time - which is ignored.
      unit - which is ignored.
      Returns:
      always true.
    • unlock

      public void unlock()
      The lock has never been taken so no effect.
      Specified by:
      unlock in interface Lock
    • newCondition

      public Condition newCondition()
      Not supported.
      Specified by:
      newCondition in interface Lock
      Returns:
      never returns.
      Throws:
      UnsupportedOperationException - if used.