Package io.temporal.workflow
Interface WorkflowLock
-
public interface WorkflowLockWorkflow lock is an alternative toLockthat is deterministic and compatible with Temporal's concurrency model. API is designed to be used in a workflow code only. It is not allowed to be used in an activity code.In Temporal concurrency model, only one thread in a workflow code can execute at a time.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanisHeld()Checks if a lock is held.voidlock()Acquires the lock.booleantryLock()Acquires the lock only if it is free at the time of invocation.booleantryLock(java.time.Duration timeout)Acquires the lock if it is free within the given waiting time.voidunlock()Releases the lock.
-
-
-
Method Detail
-
lock
void lock()
Acquires the lock.- Throws:
CanceledFailure- if thread (or currentCancellationScopewas canceled).
-
tryLock
boolean tryLock()
Acquires the lock only if it is free at the time of invocation.- Returns:
- true if the lock was acquired and false otherwise
-
tryLock
boolean tryLock(java.time.Duration timeout)
Acquires the lock if it is free within the given waiting time.- Returns:
- true if the lock was acquired and false if the waiting time elapsed before the lock was acquired.
- Throws:
CanceledFailure- if thread (or currentCancellationScopewas canceled).
-
unlock
void unlock()
Releases the lock.
-
isHeld
boolean isHeld()
Checks if a lock is held.- Returns:
- true if the lock is held and false otherwise.
-
-