Class ThreadPoolExecutorPlus

All Implemented Interfaces:
Executor, ExecutorService, ExecutorPlus, ResizableThreadPool
Direct Known Subclasses:
LocalAwareThreadPoolExecutorPlus, SingleThreadExecutorPlus

public class ThreadPoolExecutorPlus extends ThreadPoolExecutorBase implements ExecutorPlus
This class inherits Executor best practices from ThreadPoolExecutorBase and ThreadPoolExecutorBuilder. Most Cassandra executors should use or extend this. This class' addition is to abstract the semantics of task encapsulation to handle exceptions and ExecutorLocals. See TaskFactory for more detail.
  • Method Details

    • execute

      public void execute(Runnable run)
      Specified by:
      execute in interface Executor
      Overrides:
      execute in class ThreadPoolExecutor
    • execute

      public void execute(WithResources withResources, Runnable run)
      Description copied from interface: ExecutorPlus
      Invoke task. The invoking thread will first instantiate the resources provided before invoking task, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to: try (Closeable close = withResources.get()) { task.run(); }
      Specified by:
      execute in interface ExecutorPlus
      Parameters:
      withResources - the resources to create and hold while executing task
      run - the task to execute
    • submit

      public Future<?> submit(Runnable run)
      Description copied from interface: ExecutorPlus
      Overrides ExecutorService.submit(Runnable) to return a Cassandra Future
      Specified by:
      submit in interface ExecutorPlus
      Specified by:
      submit in interface ExecutorService
      Overrides:
      submit in class AbstractExecutorService
    • submit

      public <T> Future<T> submit(Runnable run, T result)
      Description copied from interface: ExecutorPlus
      Overrides ExecutorService.submit(Runnable, Object) to return a Cassandra Future
      Specified by:
      submit in interface ExecutorPlus
      Specified by:
      submit in interface ExecutorService
      Overrides:
      submit in class AbstractExecutorService
    • submit

      public <T> Future<T> submit(Callable<T> call)
      Description copied from interface: ExecutorPlus
      Overrides ExecutorService.submit(Callable) to return a Cassandra Future
      Specified by:
      submit in interface ExecutorPlus
      Specified by:
      submit in interface ExecutorService
      Overrides:
      submit in class AbstractExecutorService
    • submit

      public <T> Future<T> submit(WithResources withResources, Runnable run, T result)
      Description copied from interface: ExecutorPlus
      Invoke task, returning a future yielding result if successful, or the abnormal termination of task otherwise. The invoking thread will first instantiate the resources provided before invoking task, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to: try (Closeable close = withResources.get()) { task.run(); return result; }
      Specified by:
      submit in interface ExecutorPlus
      Parameters:
      withResources - the resources to create and hold while executing task
      run - the task to execute
      result - the result if successful
    • submit

      public Future<?> submit(WithResources withResources, Runnable run)
      Description copied from interface: ExecutorPlus
      Invoke task, returning a future yielding null if successful, or the abnormal termination of task otherwise. The invoking thread will first instantiate the resources provided before invoking task, so that thread state may be modified and cleaned up try (Closeable close = withResources.get()) { task.run(); return null; }
      Specified by:
      submit in interface ExecutorPlus
      Parameters:
      withResources - the resources to create and hold while executing task
      run - the task to execute
    • submit

      public <T> Future<T> submit(WithResources withResources, Callable<T> call)
      Description copied from interface: ExecutorPlus
      Invoke task, returning a future representing this computation. The invoking thread will first instantiate the resources provided before invoking task, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to: try (Closeable close = withResources.get()) { return task.call(); }
      Specified by:
      submit in interface ExecutorPlus
      Parameters:
      withResources - the resources to create and hold while executing task
      call - the task to execute
    • inExecutor

      public boolean inExecutor()
      Specified by:
      inExecutor in interface ExecutorPlus
      Returns:
      true iff the caller is a worker thread actively serving this executor
    • newTaskFor

      protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value)
      Overrides:
      newTaskFor in class AbstractExecutorService
    • newTaskFor

      protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable)
      Overrides:
      newTaskFor in class AbstractExecutorService
    • getMaxTasksQueued

      public int getMaxTasksQueued()
      Specified by:
      getMaxTasksQueued in interface ResizableThreadPool