Interface IThreadPool

All Superinterfaces:
AutoCloseable

public interface IThreadPool extends AutoCloseable
thread pool abstraction provided by the work manager. Threadpools are intimately related to work units in that the threads of one pool define outer boundaries for work units. Nested executeAs(Runnable, boolean) executions on the same pool will share one work unit, while switching from one pool to another will lead to independent work units. Threads not owned by this pool may be joined into this pool (and hence the workunit mechanism and the max concurrency config) via the executeAs method.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Terminate this thread pool (not waiting for tasks to complete) and unregister it with the work manager
    execute(boolean block, Runnable... runnables)
    short hand method.
    execute(boolean block, Collection<? extends Runnable> runnables)
    Execute the passed on tasks concurrently within the bounds of the pools configured maximal concurrency.
    void
    executeAs(Runnable runnable, boolean maxconcurrency)
    Incorporate the current thread logically into the pool, if it is not one of the pool's threads and execute the runnable.
    <T> T
    executeAs(Callable<T> runnable, boolean maxconcurrency)
    Like above, but excepting a Callable and thereby providing for an exception flow and a return value
    <T, E extends Exception>
    T
    getAs(ThrowingSupplier<T,E> supplier, boolean observeMaxConcurrency)
    Like above, but excepting a ThrowingSupplier and thereby providing for an exception flow and a return value
    int
    get the max achieved concurrency
    int
    sets the max concurrency for this thread pool.
    boolean
    checks whether a given thread is of this pool
    <E extends Exception>
    void
    runAs(ThrowingRunnable<E> runnable, boolean maxconcurrency)
    Like above, but excepting a ThrowingRunnable and thereby providing for a user defined exception.
    void
    setMaxConcurrency(int maxconcurrency)
    sets the max concurrency for this thread pool.
  • Method Details

    • execute

      List<Future<?>> execute(boolean block, Collection<? extends Runnable> runnables)
      Execute the passed on tasks concurrently within the bounds of the pools configured maximal concurrency.

      In case a non-blocking execution is required, all tasks will be put into the threadpool's task queue. In extreme cases this may imply that no task will be started before the current thread returns to the pool.
      In particular, if the calling thread is from the same pool, it is crucial to not have the calling thread wait for the completion of the tasks, as those may never get started as all the pool's threads are busy. If a number of tasks need to be completed and the current thread must not return to the pool before completion, this method should be called indicating a blocking execution

      Parameters:
      runnables - an array of runnables to be executed.
      block - if true the current thread will not return until all runnables have executed. If false, the current thread will return immediately.
      Returns:
      Futures representing the work in progress or already done, if block is passed as true
      Throws:
      WorkException - if there occurred an uncaught and non-severe exception during execution of a runnable. Any runnables that has not been started yet will not be started at all.
    • execute

      List<Future<?>> execute(boolean block, Runnable... runnables)
      short hand method.
      Parameters:
      runnables -
      block - if true the current thread will not return until all runnables have executed. If false, the current thread will not return if it is from the same thread pool and will return otherwise.
      Returns:
      Futures representing the work in progress or already done, if block is passed as true
    • setMaxConcurrency

      void setMaxConcurrency(int maxconcurrency)
      sets the max concurrency for this thread pool. This number of threads is guaranteed to be made available if needed. Any more active jobs will be queued
    • getMaxConcurrency

      int getMaxConcurrency()
      sets the max concurrency for this thread pool. This number of threads is guaranteed to be made available if needed. Any more active jobs will be queued
    • getMaxAchievedConcurrency

      int getMaxAchievedConcurrency()
      get the max achieved concurrency
    • isPoolThread

      boolean isPoolThread(Thread t)
      checks whether a given thread is of this pool
    • executeAs

      void executeAs(Runnable runnable, boolean maxconcurrency)
      Incorporate the current thread logically into the pool, if it is not one of the pool's threads and execute the runnable. While this may lead to an effective increase of overall concurrency, some frameworks leave no choice between risking deadlocks when switching threads or not being able to attach a suitable thread context when not switching threads (e.g. session invalidation in Jetty)... If maxconcurrency is set to true, the calling thread may need to wait in order to not exceed our configured max concurrency
    • executeAs

      <T> T executeAs(Callable<T> runnable, boolean maxconcurrency) throws Exception
      Like above, but excepting a Callable and thereby providing for an exception flow and a return value
      Throws:
      Exception
    • getAs

      <T, E extends Exception> T getAs(ThrowingSupplier<T,E> supplier, boolean observeMaxConcurrency) throws E
      Like above, but excepting a ThrowingSupplier and thereby providing for an exception flow and a return value
      Throws:
      E extends Exception
    • runAs

      <E extends Exception> void runAs(ThrowingRunnable<E> runnable, boolean maxconcurrency) throws E
      Like above, but excepting a ThrowingRunnable and thereby providing for a user defined exception.
      Throws:
      E extends Exception
    • close

      void close()
      Terminate this thread pool (not waiting for tasks to complete) and unregister it with the work manager
      Specified by:
      close in interface AutoCloseable