Class CallableWorker<T>

java.lang.Object
org.ldaptive.concurrent.CallableWorker<T>
Type Parameters:
T - type of result from the callable

public class CallableWorker<T> extends Object
Executes callable tasks asynchronously.
  • Field Details

    • DEFAULT_NUM_THREADS

      private static final int DEFAULT_NUM_THREADS
      Default size of the thread pool.
    • MAX_QUEUE_SIZE

      private static final int MAX_QUEUE_SIZE
      Maximum task queue size, value is 65535.
      See Also:
    • logger

      protected final Logger logger
      Logger for this class.
    • executorService

      private final ExecutorService executorService
      Executor service.
    • timeout

      private final Duration timeout
      Time to wait for results.
  • Constructor Details

    • CallableWorker

      public CallableWorker(String poolName)
      Creates a new callable worker with a fixed sized thread pool. The size of the thread pool is set to twice the number of available processors. See Runtime.availableProcessors().
      Parameters:
      poolName - name to designate on the thread pool
    • CallableWorker

      public CallableWorker(String poolName, Duration time)
      Creates a new callable worker with a fixed sized thread pool. The size of the thread pool is set to twice the number of available processors. See Runtime.availableProcessors().
      Parameters:
      poolName - name to designate on the thread pool
      time - to wait for a result before interrupting execution
    • CallableWorker

      public CallableWorker(String poolName, int numThreads)
      Creates a new callable worker with a fixed sized thread pool.
      Parameters:
      poolName - name to designate on the thread pool
      numThreads - size of the thread pool
    • CallableWorker

      public CallableWorker(String poolName, int numThreads, Duration time)
      Creates a new callable worker with a fixed sized thread pool.
      Parameters:
      poolName - name to designate on the thread pool
      numThreads - size of the thread pool
      time - to wait for a result before interrupting execution
    • CallableWorker

      public CallableWorker(ExecutorService es)
      Creates a new callable worker.
      Parameters:
      es - executor service to run callables
    • CallableWorker

      public CallableWorker(ExecutorService es, Duration time)
      Creates a new callable worker.
      Parameters:
      es - executor service to run callables
      time - to wait for a result before interrupting execution
  • Method Details

    • execute

      public List<ExecutionException> execute(Callable<T> callable, int count, Consumer<T> consumer)
      Executes all callables and provides each result to the supplied consumer.
      Parameters:
      callable - callable to execute
      count - number of times to execute the supplied callable
      consumer - to process callable results
      Returns:
      list of exceptions thrown during the execution
    • execute

      public List<ExecutionException> execute(List<Callable<T>> callables, Consumer<T> consumer)
      Executes all callables and provides each result to the supplied consumer. Note that the consumer is invoked in a synchronous fashion, waiting for each result from the callables.
      Parameters:
      callables - callables to execute
      consumer - to process callable results
      Returns:
      list of exceptions thrown during the execution
    • shutdown

      public void shutdown()
      Shutdown the underlying executor service.