- Type Parameters:
A
- the target state type
A lock-free command executor which guarantees the execution of commands in sequence.
It allows to eliminate race conditions when accessing a target holding a shared state.
It is backed by a multiple producer/single consumer queue storing the commands which are executed in the execute(java.util.function.Consumer)
method by a calling thread which was able to
acquire the lock.
- Since:
- 1.6
- Author:
- Jeremy Kuhn
-
Constructor Summary
ConstructorDescriptionCommandExecutor
(A target) Creates a command executor on the specified target. -
Method Summary
-
Constructor Details
-
CommandExecutor
Creates a command executor on the specified target.
- Parameters:
target
- the target state
-
-
Method Details
-
getTarget
Returns the target state.
- Returns:
- the target
-
execute
Executes the specified command.
The command is enqueued and eventually executed by the thread which was able to acquire the lock. As result execution can be synchronous or asynchronous depending on the concurrency level (i.e. how many threads are executing commands concurrently).
- Parameters:
command
- the command to execute
-