Class ExtendedScheduledExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- java.util.concurrent.ScheduledThreadPoolExecutor
-
- io.hekate.util.async.ExtendedScheduledExecutor
-
- All Implemented Interfaces:
Executor
,ExecutorService
,ScheduledExecutorService
public class ExtendedScheduledExecutor extends ScheduledThreadPoolExecutor
Extended version ofScheduledThreadPoolExecutor
.New methods that are provided by this executor are:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
-
Constructor Summary
Constructors Constructor Description ExtendedScheduledExecutor(int corePoolSize)
Constructs a new instance.ExtendedScheduledExecutor(int corePoolSize, RejectedExecutionHandler handler)
Constructs a new instance.ExtendedScheduledExecutor(int corePoolSize, ThreadFactory threadFactory)
Constructs a new instance.ExtendedScheduledExecutor(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler)
Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <V> RunnableScheduledFuture<V>
decorateTask(Runnable runnable, RunnableScheduledFuture<V> task)
ScheduledFuture<?>
repeatAtFixedRate(RepeatingRunnable command, long initialDelay, long period, TimeUnit unit)
Schedules the specified repeating command to be executed at fixed rate.ScheduledFuture<?>
repeatWithFixedDelay(RepeatingRunnable command, long initialDelay, long delay, TimeUnit unit)
Schedules the specified repeating command to be executed with fixed delay.-
Methods inherited from class java.util.concurrent.ScheduledThreadPoolExecutor
decorateTask, execute, getContinueExistingPeriodicTasksAfterShutdownPolicy, getExecuteExistingDelayedTasksAfterShutdownPolicy, getQueue, getRemoveOnCancelPolicy, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, setContinueExistingPeriodicTasksAfterShutdownPolicy, setExecuteExistingDelayedTasksAfterShutdownPolicy, setRemoveOnCancelPolicy, shutdown, shutdownNow, submit, submit, submit
-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, terminated, toString
-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated
-
-
-
-
Constructor Detail
-
ExtendedScheduledExecutor
public ExtendedScheduledExecutor(int corePoolSize)
Constructs a new instance.- Parameters:
corePoolSize
- Thread pool size.
-
ExtendedScheduledExecutor
public ExtendedScheduledExecutor(int corePoolSize, ThreadFactory threadFactory)
Constructs a new instance.- Parameters:
corePoolSize
- Thread pool size.threadFactory
- Thread factory.
-
ExtendedScheduledExecutor
public ExtendedScheduledExecutor(int corePoolSize, RejectedExecutionHandler handler)
Constructs a new instance.- Parameters:
corePoolSize
- Thread pool size.handler
- Rejected execution handler.
-
ExtendedScheduledExecutor
public ExtendedScheduledExecutor(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler)
Constructs a new instance.- Parameters:
corePoolSize
- Thread pool size.threadFactory
- Thread factory.handler
- Rejected execution handler.
-
-
Method Detail
-
repeatAtFixedRate
public ScheduledFuture<?> repeatAtFixedRate(RepeatingRunnable command, long initialDelay, long period, TimeUnit unit)
Schedules the specified repeating command to be executed at fixed rate.Behavior of this method is similar to the behavior of the
ScheduledThreadPoolExecutor.scheduleAtFixedRate(Runnable, long, long, TimeUnit)
method, except that it accepts an instance ofRepeatingRunnable
instead of aRunnable
interface.After each execution the result of
RepeatingRunnable.run()
method's will be checked. If it returnstrue
then the command will be re-scheduled again; if it returnsfalse
then execution will be cancelled and the command will not be executed anymore.- Parameters:
command
- Command.initialDelay
- Initial delay before the first execution.period
- Interval between executions.unit
- Time unit ofinitialDelay
andperiod
parameters.- Returns:
- Future of a scheduled command.
-
repeatWithFixedDelay
public ScheduledFuture<?> repeatWithFixedDelay(RepeatingRunnable command, long initialDelay, long delay, TimeUnit unit)
Schedules the specified repeating command to be executed with fixed delay.Behavior of this method is similar to the behavior of the
ScheduledThreadPoolExecutor.scheduleWithFixedDelay(Runnable, long, long, TimeUnit)
method, except that it accepts an instance ofRepeatingRunnable
instead of aRunnable
interface.After each execution the result of
RepeatingRunnable.run()
method's will be checked. If it returnstrue
then the command will be re-scheduled again; if it returnsfalse
then execution will be cancelled and the command will not be executed anymore.- Parameters:
command
- Command.initialDelay
- Initial delay before the first execution.delay
- Delay between executions.unit
- Time unit ofinitialDelay
anddelay
parameters.- Returns:
- Future of a scheduled command.
-
decorateTask
protected <V> RunnableScheduledFuture<V> decorateTask(Runnable runnable, RunnableScheduledFuture<V> task)
- Overrides:
decorateTask
in classScheduledThreadPoolExecutor
-
-