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 TypeMethodDescriptionboolean
exit
(boolean blocking) Shuts thisAbstractTaskQueueExecutor
down by gracefully stopping the worker threads.boolean
Queues a task to be executed by any available worker thread.void
setErrorHandler
(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.boolean
Removes 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:AbstractTaskQueueExecutor
Queues a task to be executed by any available worker thread.- Specified by:
queue
in classAbstractTaskQueueExecutor
- Parameters:
task
- The task to queue- Returns:
true
if 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:
unqueue
in classAbstractTaskQueueExecutor
- Parameters:
task
- The task to remove- Returns:
true
if the task was queued previously and removed successfully- See Also:
-
exit
public boolean exit(boolean blocking) Shuts thisAbstractTaskQueueExecutor
down by gracefully stopping the worker threads.A no-op that always returns
false
.- Specified by:
exit
in classAbstractTaskQueueExecutor
- Parameters:
blocking
-true
to wait for all worker threads to exit- Returns:
true
if the calling thread was interrupted while waiting for the worker threads to exit
-
setErrorHandler
Description copied from class:AbstractTaskQueueExecutor
Sets 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:
setErrorHandler
in classAbstractTaskQueueExecutor
- Parameters:
errorHandler
- The error handler, ornull
to remove an existing error handler
-