Package org.opends.server.util
Class CronExecutorService
java.lang.Object
org.opends.server.util.CronExecutorService
- All Implemented Interfaces:
Executor
,ExecutorService
,ScheduledExecutorService
Implements a
ScheduledExecutorService
on top of a cached thread pool
to achieve UNIX's cron-like capabilities.
This executor service is implemented with two underlying executor services:
a single-thread scheduled executor
which allows to start tasks based on a schedulea cached thread pool
which allows to run several tasks concurrently, adjusting the thread pool size when necessary. In particular, when the number of tasks to run concurrently is bigger than the tread pool size, then new threads are spawned. The thread pool is then shrinked when threads sit idle with no tasks to execute.
All the tasks submitted to the current class are 1. scheduled by the single-thread scheduled executor and 2. finally executed by the cached thread pool.
Because of this setup, the assumptions of scheduleWithFixedDelay(Runnable, long, long, TimeUnit)
cannot be
fulfilled, so calling this method will throw a UnsupportedOperationException
.
(OPENDJ-3487) Current (Sept. 2017) OpenDJ threads that may be replaced by using the current class:
- Idle Time Limit Thread
- Task Scheduler Thread
- Rejected: Time Thread - high resolution thread
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
Helper for representing zero delay constant.static final ScheduledExecutorService
A Null CronExecutor, used during server shutdown. -
Constructor Summary
ConstructorDescriptionCronExecutorService
(ServerContext serverContext) Build cron executor with the provided server context. -
Method Summary
Modifier and TypeMethodDescriptionboolean
awaitTermination
(long timeout, TimeUnit unit) void
invokeAll
(Collection<? extends Callable<T>> tasks) invokeAll
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) <T> T
invokeAny
(Collection<? extends Callable<T>> tasks) <T> T
invokeAny
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) boolean
boolean
<V> ScheduledFuture<V>
scheduleAtFixedRate
(Runnable task, long initialDelay, long period, TimeUnit unit) scheduleWithFixedDelay
(Runnable task, long initialDelay, long delay, TimeUnit unit) void
shutdown()
Future<?>
<T> Future<T>
<T> Future<T>
-
Field Details
-
EXECUTE_IMMEDIATELY_AND_EVERY
public static final long EXECUTE_IMMEDIATELY_AND_EVERYHelper for representing zero delay constant.- See Also:
-
NULL_CRON_EXECUTOR
A Null CronExecutor, used during server shutdown. It reports being already shutdown and all scheduled tasks are ignored, returning a completed result.
-
-
Constructor Details
-
CronExecutorService
Build cron executor with the provided server context.- Parameters:
serverContext
- The server context.
-
-
Method Details
-
execute
-
submit
- Specified by:
submit
in interfaceExecutorService
-
submit
- Specified by:
submit
in interfaceExecutorService
-
submit
- Specified by:
submit
in interfaceExecutorService
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit unit) - Specified by:
scheduleAtFixedRate
in interfaceScheduledExecutorService
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit) - Specified by:
scheduleWithFixedDelay
in interfaceScheduledExecutorService
-
schedule
- Specified by:
schedule
in interfaceScheduledExecutorService
-
schedule
- Specified by:
schedule
in interfaceScheduledExecutorService
-
invokeAny
- Specified by:
invokeAny
in interfaceExecutorService
-
invokeAny
- Specified by:
invokeAny
in interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) - Specified by:
invokeAll
in interfaceExecutorService
-
invokeAll
- Specified by:
invokeAll
in interfaceExecutorService
-
awaitTermination
- Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
-
shutdown
public void shutdown()- Specified by:
shutdown
in interfaceExecutorService
-
shutdownNow
- Specified by:
shutdownNow
in interfaceExecutorService
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminated
in interfaceExecutorService
-