Package org.omegazero.common.event
Class SynchronousTaskQueueExecutor
java.lang.Object
org.omegazero.common.event.AbstractTaskQueueExecutor
org.omegazero.common.event.SynchronousTaskQueueExecutor
An
AbstractTaskQueueExecutor running all tasks passed to queue methods synchronously (in the same thread).
This class is thread-safe. It has little real-world value and should only be used for testing purposes.
- Since:
- 2.12.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanexit(boolean blocking) Shuts thisAbstractTaskQueueExecutordown by gracefully stopping the worker threads.booleanQueues a task to be executed by any available worker thread.voidsetErrorHandler(Consumer<Throwable> errorHandler) Sets the error handler that will be called when an error occurs while executing a task in any of the worker threads.booleanRemoves the given task from the queue.Methods inherited from class org.omegazero.common.event.AbstractTaskQueueExecutor
exit, queue, queue, queue
-
Constructor Details
-
SynchronousTaskQueueExecutor
public SynchronousTaskQueueExecutor()Creates a newSynchronousTaskQueueExecutor.
-
-
Method Details
-
queue
Description copied from class:AbstractTaskQueueExecutorQueues a task to be executed by any available worker thread.- Specified by:
queuein classAbstractTaskQueueExecutor- Parameters:
task- The task to queue- Returns:
trueif the task was successfully queued- See Also:
-
unqueue
Removes the given task from the queue.A no-op that always returns
false, since tasks are not queued but executed synchronously.- Specified by:
unqueuein classAbstractTaskQueueExecutor- Parameters:
task- The task to remove- Returns:
trueif the task was queued previously and removed successfully- See Also:
-
exit
public boolean exit(boolean blocking) Shuts thisAbstractTaskQueueExecutordown by gracefully stopping the worker threads.A no-op that always returns
false.- Specified by:
exitin classAbstractTaskQueueExecutor- Parameters:
blocking-trueto wait for all worker threads to exit- Returns:
trueif the calling thread was interrupted while waiting for the worker threads to exit
-
setErrorHandler
Description copied from class:AbstractTaskQueueExecutorSets the error handler that will be called when an error occurs while executing a task in any of the worker threads.If this handler is not set, the error will be printed to
stderr.- Specified by:
setErrorHandlerin classAbstractTaskQueueExecutor- Parameters:
errorHandler- The error handler, ornullto remove an existing error handler
-