Class LockUtil

java.lang.Object
io.camunda.zeebe.util.LockUtil

public final class LockUtil extends Object
Utility class for common tasks with Lock instances.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    withLock(Lock lock, Runnable runnable)
    Runs the given operation only when the lock has been obtained.
    static void
    withLock(Lock lock, Runnable runnable, org.agrona.ErrorHandler errorHandler)
    Runs the given operation only when the lock has been obtained.
    static <V> V
    withLock(Lock lock, Supplier<V> callable)
    Runs the given operation only when the lock has been obtained.
    static <V> V
    withLock(Lock lock, Supplier<V> callable, org.agrona.ErrorHandler errorHandler)
    Runs the given operation only when the lock has been obtained.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • withLock

      public static void withLock(Lock lock, Runnable runnable)
      Runs the given operation only when the lock has been obtained. Locks interruptibly, meaning if the thread is interrupted while waiting for the lock, the runnable is not executed.
      Parameters:
      lock - the lock to acquire
      runnable - the operation to run
    • withLock

      public static <V> V withLock(Lock lock, Supplier<V> callable)
      Runs the given operation only when the lock has been obtained. Locks interruptibly, meaning if the thread is interrupted while waiting for the lock, the runnable is not executed.
      Parameters:
      lock - the lock to acquire
      callable - the operation to run
    • withLock

      public static void withLock(Lock lock, Runnable runnable, org.agrona.ErrorHandler errorHandler)
      Runs the given operation only when the lock has been obtained. Locks interruptibly, meaning if the thread is interrupted while waiting for the lock, the runnable is not executed. If interrupted, calls the error handler.
      Parameters:
      lock - the lock to acquire
      runnable - the operation to run
      errorHandler - called if an error occurs during interruption
    • withLock

      public static <V> V withLock(Lock lock, Supplier<V> callable, org.agrona.ErrorHandler errorHandler)
      Runs the given operation only when the lock has been obtained. Locks interruptibly, meaning if the thread is interrupted while waiting for the lock, the runnable is not executed. If interrupted, calls the error handler.
      Parameters:
      lock - the lock to acquire
      callable - the operation to run
      errorHandler - called if an error occurs during interruption