Package com.zfabrik.work

## Interface IThreadPool

-     public interface IThreadPool

  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

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `execute​(boolean block, java.lang.Runnable... runnables)` | short hand method.
    `void` | `execute​(boolean block, java.util.Collection<? extends java.lang.Runnable> runnables)` | Execute the passed on tasks concurrently within the bounds of the pools configured maximal concurrency.
    `void` | `executeAs​(java.lang.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​(java.util.concurrent.Callable<T> runnable, boolean maxconcurrency)` | Like above, but excepting a callable and thereby providing for an exception flow and a return value
    `int` | `getMaxAchievedConcurrency()` | get the max achieved concurrency
    `int` | `getMaxConcurrency()` | sets the max concurrency for this thread pool.
    `boolean` | `isPoolThread​(java.lang.Thread t)` | checks whether a given thread is of this pool
    `void` | `setMaxConcurrency​(int maxconcurrency)` | sets the max concurrency for this thread pool.

- - ### Method Detail

    - #### execute

          void execute​(boolean block,
                       java.util.Collection<? extends java.lang.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.
      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

          void execute​(boolean block,
                       java.lang.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.

    - #### 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​(java.lang.Thread t)

      checks whether a given thread is of this pool

    - #### executeAs

          void executeAs​(java.lang.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​(java.util.concurrent.Callable<T> runnable,
                          boolean maxconcurrency)
                   throws java.lang.Exception

      Like above, but excepting a callable and thereby providing for an exception flow and a return value
      Throws:
        `java.lang.Exception`