Interface TaskManager
- All Known Implementing Classes:
DefaultTaskManager
public interface TaskManager
Manages background task ran using
ExecutorService
.
It can be treated as adapter on ExecutorService
, that adds support for:
- task monitoring,
- system wide thread pool,
- manageable pool size,
- throttling,
- easy scheduling and conditioning.
Overall it is always preferable to use TaskManager
instead of ExecutorService
or Thread
. It is designed for short tasks, tasks that share the same memory pool (JVM) as main job,
tasks that blocks request execution and all other kinds of light tasks, that don't need to be plugin state aware.
If you need support for long running tasks, tasks that must work even after restart, tasks that may wait for execution,
or even can be started on different machine, you should consider using BackgroundJobManager
.
It provides support for heavy jobs and is plugin aware.
Usage:
Some source code here
- See Also:
-
BackgroundJobManager
ScheduledFuture
FutureTask
-
Method Summary
Modifier and TypeMethodDescriptionReturnsScheduledExecutorService
that provide the same functionality asTaskManager
ReturnsThreadFactory
that provide the same functionality asTaskManager
createThread
(Runnable task) Start new monitored thread outside of thread pool.Future<?>
Runs provided task as soon as there is free thread in the pool.<T> Future<T>
Runs provided task as soon as there is free thread in the pool.scheduleTask
(Runnable task, ScheduleConfig<Void> scheduleConfig) Runs provided task using provided config<T> ScheduledFuture<T>
scheduleTask
(Callable<T> task, ScheduleConfig<T> scheduleConfig) Runs provided task using provided config
-
Method Details
-
createThread
Start new monitored thread outside of thread pool. It's equivalent ofThread(Runnable)
- Parameters:
task
- task to run- Returns:
- not started thread with monitoring
-
runTask
Runs provided task as soon as there is free thread in the pool.- Parameters:
task
- task to run- Returns:
- the same
Future
that would be returned byExecutorService
-
runTask
Runs provided task as soon as there is free thread in the pool.- Parameters:
task
- task to run- Returns:
- the same
Future
that would be returned byExecutorService
-
scheduleTask
Runs provided task using provided config- Parameters:
task
- task to runscheduleConfig
- config for scheduling task- Returns:
- controller for scheduled task
-
scheduleTask
Runs provided task using provided config- Parameters:
task
- task to runscheduleConfig
- config for scheduling task- Returns:
- controller for scheduled task
-
asThreadFactory
ThreadFactory asThreadFactory()ReturnsThreadFactory
that provide the same functionality asTaskManager
- Returns:
ThreadFactory
-
asExecutorService
AdvancedScheduledExecutorService asExecutorService()ReturnsScheduledExecutorService
that provide the same functionality asTaskManager
- Returns:
ScheduledExecutorService
-