Class SynchronousTaskQueueExecutor

java.lang.Object
org.omegazero.common.event.AbstractTaskQueueExecutor
org.omegazero.common.event.SynchronousTaskQueueExecutor

public class SynchronousTaskQueueExecutor extends AbstractTaskQueueExecutor
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 Details

  • Method Details

    • queue

      public boolean queue(Task task)
      Description copied from class: AbstractTaskQueueExecutor
      Queues a task to be executed by any available worker thread.
      Specified by:
      queue in class AbstractTaskQueueExecutor
      Parameters:
      task - The task to queue
      Returns:
      true if the task was successfully queued
      See Also:
    • unqueue

      public boolean unqueue(Task task)
      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 class AbstractTaskQueueExecutor
      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 this AbstractTaskQueueExecutor down by gracefully stopping the worker threads.

      A no-op that always returns false.

      Specified by:
      exit in class AbstractTaskQueueExecutor
      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

      public void setErrorHandler(Consumer<Throwable> errorHandler)
      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 class AbstractTaskQueueExecutor
      Parameters:
      errorHandler - The error handler, or null to remove an existing error handler