Package org.opends.server.util
Class CronExecutorService
- java.lang.Object
-
- org.opends.server.util.CronExecutorService
-
- All Implemented Interfaces:
Executor,ExecutorService,ScheduledExecutorService
public final class CronExecutorService extends Object implements ScheduledExecutorService
Implements aScheduledExecutorServiceon top of acached thread poolto achieve UNIX's cron-like capabilities.This executor service is implemented with two underlying executor services:
a single-thread scheduled executorwhich allows to start tasks based on a schedulea cached thread poolwhich 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 aUnsupportedOperationException.(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
Fields Modifier and Type Field Description static longEXECUTE_IMMEDIATELY_AND_EVERYHelper for representing zero delay constant.
-
Constructor Summary
Constructors Constructor Description CronExecutorService()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitTermination(long timeout, TimeUnit unit)voidexecute(Runnable task)<T> List<Future<T>>invokeAll(Collection<? extends Callable<T>> tasks)<T> List<Future<T>>invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)<T> TinvokeAny(Collection<? extends Callable<T>> tasks)<T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)booleanisShutdown()booleanisTerminated()ScheduledFuture<?>schedule(Runnable task, long delay, TimeUnit unit)<V> ScheduledFuture<V>schedule(Callable<V> task, long delay, TimeUnit unit)ScheduledFuture<?>scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit unit)ScheduledFuture<?>scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit)voidshutdown()List<Runnable>shutdownNow()Future<?>submit(Runnable task)<T> Future<T>submit(Runnable task, T result)<T> Future<T>submit(Callable<T> task)
-
-
-
Field Detail
-
EXECUTE_IMMEDIATELY_AND_EVERY
public static final long EXECUTE_IMMEDIATELY_AND_EVERY
Helper for representing zero delay constant.- See Also:
- Constant Field Values
-
-
Method Detail
-
submit
public Future<?> submit(Runnable task)
- Specified by:
submitin interfaceExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submitin interfaceExecutorService
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submitin interfaceExecutorService
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit unit)
- Specified by:
scheduleAtFixedRatein interfaceScheduledExecutorService
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit)
- Specified by:
scheduleWithFixedDelayin interfaceScheduledExecutorService
-
schedule
public <V> ScheduledFuture<V> schedule(Callable<V> task, long delay, TimeUnit unit)
- Specified by:
schedulein interfaceScheduledExecutorService
-
schedule
public ScheduledFuture<?> schedule(Runnable task, long delay, TimeUnit unit)
- Specified by:
schedulein interfaceScheduledExecutorService
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
- Specified by:
invokeAnyin interfaceExecutorService
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
- Specified by:
invokeAnyin interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
- Specified by:
invokeAllin interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
- Specified by:
invokeAllin interfaceExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException- Specified by:
awaitTerminationin interfaceExecutorService- Throws:
InterruptedException
-
shutdown
public void shutdown()
- Specified by:
shutdownin interfaceExecutorService
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNowin interfaceExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminatedin interfaceExecutorService
-
-