Class DwAsyncPoolImpl

java.lang.Object
net.datenwerke.async.DwAsyncPoolImpl
All Implemented Interfaces:
DwAsyncPool

public class DwAsyncPoolImpl extends Object implements DwAsyncPool
Default implementation of DwAsyncPool
  • Constructor Summary

    Constructors
    Constructor
    Description
    DwAsyncPoolImpl(String threadLabel)
    Creates a new pool with the given label.
    Creates a new thread pool from the given executor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    awaitTermination(long timeout, TimeUnit unit)
    Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
    int
    Returns the approximate number of threads that are actively executing tasks.
    long
    Returns the approximate total number of tasks that have completed execution.
    int
    Returns the core number of threads.
    Returns the underlying ExecutorService object.
    int
    Returns the current number of threads in the pool.
    long
    Returns the approximate total number of tasks that have ever been scheduled for execution.
    boolean
    Returns true if the pool has been shut down (orderly).
    boolean
    Returns true if the pool has been terminated
    void
    Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
    Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
    Submits a Runnable task for execution and returns a Future representing that task.
    <T> Future<T>
    submit(Runnable task, T result)
    Submits a Runnable task for execution and returns a Future representing that task.
    <T> Future<T>
    submit(Callable<T> task)
    Submits a value-returning task for execution and returns a Future representing the pending results of the task.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • submit

      public <T> Future<T> submit(Callable<T> task)
      Description copied from interface: DwAsyncPool
      Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get method will return the task's result upon successful completion.
      Specified by:
      submit in interface DwAsyncPool
      Parameters:
      task -
      See Also:
    • submit

      public Future<?> submit(Runnable task)
      Description copied from interface: DwAsyncPool
      Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return null upon successful completion.
      Specified by:
      submit in interface DwAsyncPool
      Parameters:
      task -
      See Also:
    • submit

      public <T> Future<T> submit(Runnable task, T result)
      Description copied from interface: DwAsyncPool
      Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.
      Specified by:
      submit in interface DwAsyncPool
      Parameters:
      task -
      See Also:
    • awaitTermination

      public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
      Description copied from interface: DwAsyncPool
      Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
      Specified by:
      awaitTermination in interface DwAsyncPool
      Parameters:
      timeout -
      unit -
      Throws:
      InterruptedException
      See Also:
    • getExecutorService

      public ExecutorService getExecutorService()
      Returns the underlying ExecutorService object.
    • getActiveCount

      public int getActiveCount()
      Description copied from interface: DwAsyncPool
      Returns the approximate number of threads that are actively executing tasks.
      Specified by:
      getActiveCount in interface DwAsyncPool
      Returns:
      the number of threads
      See Also:
    • getPoolSize

      public int getPoolSize()
      Description copied from interface: DwAsyncPool
      Returns the current number of threads in the pool.
      Specified by:
      getPoolSize in interface DwAsyncPool
      Returns:
      the number of threads
      See Also:
    • getCorePoolSize

      public int getCorePoolSize()
      Description copied from interface: DwAsyncPool
      Returns the core number of threads.
      Specified by:
      getCorePoolSize in interface DwAsyncPool
      Returns:
      the core number of threads
      See Also:
    • getTaskCount

      public long getTaskCount()
      Description copied from interface: DwAsyncPool
      Returns the approximate total number of tasks that have ever been scheduled for execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation.
      Specified by:
      getTaskCount in interface DwAsyncPool
      Returns:
      the number of threads
      See Also:
    • getCompletedTaskCount

      public long getCompletedTaskCount()
      Description copied from interface: DwAsyncPool
      Returns the approximate total number of tasks that have completed execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation, but one that does not ever decrease across successive calls.
      Specified by:
      getCompletedTaskCount in interface DwAsyncPool
      Returns:
      the number of threads
      See Also:
    • isShutdown

      public boolean isShutdown()
      Description copied from interface: DwAsyncPool
      Returns true if the pool has been shut down (orderly).
      Specified by:
      isShutdown in interface DwAsyncPool
    • isTerminated

      public boolean isTerminated()
      Description copied from interface: DwAsyncPool
      Returns true if the pool has been terminated
      Specified by:
      isTerminated in interface DwAsyncPool
    • shutdown

      public void shutdown()
      Description copied from interface: DwAsyncPool
      Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.

      This method does not wait for previously submitted tasks to complete execution. Use awaitTermination to do that.

      Specified by:
      shutdown in interface DwAsyncPool
      See Also:
    • shutdownNow

      public List<Runnable> shutdownNow()
      Description copied from interface: DwAsyncPool
      Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

      This method does not wait for actively executing tasks to terminate. Use awaitTermination to do that.

      There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.

      Specified by:
      shutdownNow in interface DwAsyncPool
      Returns:
      list of tasks that never commenced execution
      See Also: