Package org.ldaptive.concurrent
Class CallableWorker<T>
java.lang.Object
org.ldaptive.concurrent.CallableWorker<T>
- Type Parameters:
T- type of result from the callable
Executes callable tasks asynchronously.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intDefault size of the thread pool.private final ExecutorServiceExecutor service.protected final LoggerLogger for this class.private static final intMaximum task queue size, value is 65535.private final DurationTime to wait for results. -
Constructor Summary
ConstructorsConstructorDescriptionCallableWorker(String poolName) Creates a new callable worker with a fixed sized thread pool.CallableWorker(String poolName, int numThreads) Creates a new callable worker with a fixed sized thread pool.CallableWorker(String poolName, int numThreads, Duration time) Creates a new callable worker with a fixed sized thread pool.CallableWorker(String poolName, Duration time) Creates a new callable worker with a fixed sized thread pool.Creates a new callable worker.CallableWorker(ExecutorService es, Duration time) Creates a new callable worker. -
Method Summary
Modifier and TypeMethodDescriptionExecutes all callables and provides each result to the supplied consumer.Executes all callables and provides each result to the supplied consumer.voidshutdown()Shutdown the underlying executor service.
-
Field Details
-
DEFAULT_NUM_THREADS
private static final int DEFAULT_NUM_THREADSDefault size of the thread pool. -
MAX_QUEUE_SIZE
private static final int MAX_QUEUE_SIZEMaximum task queue size, value is 65535.- See Also:
-
logger
Logger for this class. -
executorService
Executor service. -
timeout
Time to wait for results.
-
-
Constructor Details
-
CallableWorker
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. SeeRuntime.availableProcessors().- Parameters:
poolName- name to designate on the thread pool
-
CallableWorker
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. SeeRuntime.availableProcessors().- Parameters:
poolName- name to designate on the thread pooltime- to wait for a result before interrupting execution
-
CallableWorker
Creates a new callable worker with a fixed sized thread pool.- Parameters:
poolName- name to designate on the thread poolnumThreads- size of the thread pool
-
CallableWorker
Creates a new callable worker with a fixed sized thread pool.- Parameters:
poolName- name to designate on the thread poolnumThreads- size of the thread pooltime- to wait for a result before interrupting execution
-
CallableWorker
Creates a new callable worker.- Parameters:
es- executor service to run callables
-
CallableWorker
Creates a new callable worker.- Parameters:
es- executor service to run callablestime- to wait for a result before interrupting execution
-
-
Method Details
-
execute
Executes all callables and provides each result to the supplied consumer.- Parameters:
callable- callable to executecount- number of times to execute the supplied callableconsumer- to process callable results- Returns:
- list of exceptions thrown during the execution
-
execute
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 executeconsumer- to process callable results- Returns:
- list of exceptions thrown during the execution
-
shutdown
public void shutdown()Shutdown the underlying executor service.
-