java.lang.Object
org.tentackle.session.SessionPooledExecutor
Executes runnables on a pool of sessions.
Useful to run background tasks in parallel, each task with its own session.
Useful to run background tasks in parallel, each task with its own session.
-
Constructor Summary
ConstructorsConstructorDescriptionSessionPooledExecutor(SessionPool sessionPool) Creates the executor service for a session pool. -
Method Summary
Modifier and TypeMethodDescriptionprotected ExecutorServiceCreates the executor service.
For unlimited session pools the thread pool will also be unlimited and the number of threads will be adjusted automatically, i.e.protected ThreadcreateThread(Runnable runnable) Creates a new thread.Gets the executor service.Gets the session pool.voidshutdown()Shuts down the executor service and the pool.<V> voidsubmit(Collection<Supplier<V>> tasks, long timeoutMillis, Consumer<Map<Supplier<V>, V>> successHandlers, Consumer<Map<Supplier<V>, RuntimeException>> failHandlers) Submits a collection of tasks for background execution in multiple threads of a thread pool and waits for their termination.<V> voidsubmit(Supplier<V> task, Consumer<V> successHandler, Consumer<RuntimeException> failHandler) Submits a task for execution in background by a thread pool.
-
Constructor Details
-
SessionPooledExecutor
Creates the executor service for a session pool.- Parameters:
sessionPool- the session pool
-
-
Method Details
-
getSessionPool
Gets the session pool.- Returns:
- the pool
-
getExecutorService
Gets the executor service.- Returns:
- the executor service
-
shutdown
public void shutdown()Shuts down the executor service and the pool. -
submit
public <V> void submit(Supplier<V> task, Consumer<V> successHandler, Consumer<RuntimeException> failHandler) Submits a task for execution in background by a thread pool.- Type Parameters:
V- the type returned by the task- Parameters:
task- the task to executesuccessHandler- the handler to be invoked when the task finished successfully, null if nonefailHandler- the handler to be invoked when the task failed with an exception, null if none
-
submit
public <V> void submit(Collection<Supplier<V>> tasks, long timeoutMillis, Consumer<Map<Supplier<V>, V>> successHandlers, Consumer<Map<Supplier<V>, RuntimeException>> failHandlers) Submits a collection of tasks for background execution in multiple threads of a thread pool and waits for their termination.- Type Parameters:
V- the type returned by the runners- Parameters:
tasks- the tasks to executetimeoutMillis- the timeout in milliseconds, ≤ 0 if wait infinitelysuccessHandlers- updater invoked when all runners finished, null if nonefailHandlers- updater invoked only if execution of some runner failed, null if log only as error
-
createExecutorService
Creates the executor service.
For unlimited session pools the thread pool will also be unlimited and the number of threads will be adjusted automatically, i.e. new threads are created when necessary (tasks are not queued) and unused threads are removed when no more used for a certain amount of time.
For limited session pools a fixed size thread pool is used and tasks are queued, if all threads are in use.- Returns:
- the executor service
-
createThread
Creates a new thread.- Parameters:
runnable- the runnable to run- Returns:
- the thread
-