Interface LockExecutor
- All Known Implementing Classes:
LockExecutorImpl
@ClassVersion(sourceVersion="$Id: LockExecutor.java 1185 2026-04-06 10:26:47Z tquadrat $")
@API(status=STABLE,
since="0.1.0")
public sealed interface LockExecutor
permits LockExecutorImpl
Allows to execute an operation with an obtained lock.
Use this class like below:
… final var lock = new ReentrantLock(); final var executor = LockExecutor.of( lock ); … executor.execute( () -> doSomething() ); …
- Note:
-
- If your program is using
AutoLock, you should use the corresponding methods from there.
- If your program is using
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: LockExecutor.java 1185 2026-04-06 10:26:47Z tquadrat $
- Since:
- 0.1.0
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.lang.LockExecutor"
-
Method Summary
Modifier and TypeMethodDescriptionbooleanevaluate(Constraint constraint) Evaluates the given condition.default voidDeprecated, for removal: This API element is subject to removal in a future version.<R> Optional<R> Executes the given operation.static LockExecutorCreates a newLockExecutorfrom the givenLockinstance.static LockExecutorCreates a newLockExecutorfrom the givenAutoLockinstance.voidPerforms the given action after obtaining the lock.
-
Method Details
-
evaluate
Evaluates the given condition.- Parameters:
constraint- The constraint.- Returns:
- The result of the evaluation of the condition.
- Throws:
AutoLock.ExecutionFailedException- The evaluation failed for some reason.
-
execute
@Deprecated(since="0.25.3", forRemoval=true) default void execute(Action action) throws AutoLock.ExecutionFailedException Deprecated, for removal: This API element is subject to removal in a future version.Useperform(Action)instead; basically this method was renamed to avoid the unintended use ofexecute(Operation)when anActionshould be used instead.Executes the given action.- Parameters:
action- The action.- Throws:
AutoLock.ExecutionFailedException- The action failed for some reason.
-
execute
Executes the given operation.- Type Parameters:
R- The type of the operation's result.- Parameters:
operation- The operation.- Returns:
- An instance of
Optionalthat holds the result of the operation. - Throws:
AutoLock.ExecutionFailedException- The operation failed for some reason.
-
of
-
of
-
perform
Performs the given action after obtaining the lock.
This differs from
execute(Operation)asActiondoes not return something, and a warning regarding "Result of assignment expression used" can be avoided in case theactionis used to set an attribute.- Parameters:
action- The action.- Throws:
AutoLock.ExecutionFailedException- The action failed for some reason.
-

perform(Action)instead; basically this method was renamed to avoid the unintended use ofexecute(Operation)when anActionshould be used instead.