Class LockUtils
java.lang.Object
org.aksw.commons.util.lock.LockUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TrepeatWithLock(int retryCount, int delayInMs, Lock lockSupplier, Callable<T> action) Perform an action which requires acquisition of a lock first.static <T> TrunWithLock(Lock lock, Callable<T> action) Perform an action which requires acquisition of a lock first.static voidrunWithLock(Lock lock, ThrowingRunnable action) static <T, L extends Lock>
TrunWithMgmtLock(L lock, Consumer<? super L> forceUnlock, Duration duration, Callable<T> action) Run this action with a short-lived locked.
-
Constructor Details
-
LockUtils
public LockUtils()
-
-
Method Details
-
repeatWithLock
public static <T> T repeatWithLock(int retryCount, int delayInMs, Lock lockSupplier, Callable<T> action) Perform an action which requires acquisition of a lock first. Repeated attempts are made to acquire the lock. If the lock cannot be acquired then the action is not run.- Type Parameters:
T-- Parameters:
retryCount-delayInMs-lockSupplier-action-- Returns:
-
runWithLock
-
runWithLock
-
runWithMgmtLock
public static <T, L extends Lock> T runWithMgmtLock(L lock, Consumer<? super L> forceUnlock, Duration duration, Callable<T> action) Run this action with a short-lived locked. If the lock cannot be acquired within the given time it is considered stale and forcibly unlocked. Subsequently another attempt is made to acquire the lock.
-