-
- All Implemented Interfaces:
-
java.util.concurrent.Executor,java.util.concurrent.ExecutorService
public final class CommonTaskExecutor extends AbstractExecutorService
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceCommonTaskExecutor.Task
-
Field Summary
Fields Modifier and Type Field Description public final static CommonTaskExecutorINSTANCE
-
Method Summary
Modifier and Type Method Description <T> ScheduledFuture<out Object>scheduleAtFixedRate(CommonTaskExecutor.Task<T> task, T target, long initialDelay, long period, TimeUnit unit, String name)Run {@code task}periodically providing it with{@code target}Important implementation detail here is that internally we do not hold any strong referencesto{@code target}which means it can be GCed even while periodic task is still scheduled.voidshutdown()List<Runnable>shutdownNow()booleanisShutdown()booleanisTerminated()booleanawaitTermination(long timeout, TimeUnit unit)voidexecute(Runnable command)-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAny, submit, submit -
Methods inherited from class java.util.concurrent.ExecutorService
awaitTermination, isShutdown, isTerminated, shutdown, shutdownNow -
Methods inherited from class java.util.concurrent.Executor
execute -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
scheduleAtFixedRate
<T> ScheduledFuture<out Object> scheduleAtFixedRate(CommonTaskExecutor.Task<T> task, T target, long initialDelay, long period, TimeUnit unit, String name)
Run
{@code task}periodically providing it with{@code target}Important implementation detail here is that internally we do not hold any strong referencesto
{@code target}which means it can be GCed even while periodic task is still scheduled.If
{@code target}is GCed periodic task is canceled.This method should be able to schedule task in majority of cases. The only reasonable casewhen this would fail is when task is being scheduled during JVM shutdown. In this case thismethod will return 'fake' future that can still be canceled to avoid confusing callers.
- Parameters:
task- task to run.target- target object to pass to taskinitialDelay- initialDelay, seeperiod- period, see scheduleAtFixedRateunit- unit, see scheduleAtFixedRatename- name to use in logs when task cannot be scheduled
-
shutdown
void shutdown()
-
shutdownNow
List<Runnable> shutdownNow()
-
isShutdown
boolean isShutdown()
-
isTerminated
boolean isTerminated()
-
awaitTermination
boolean awaitTermination(long timeout, TimeUnit unit)
-
-
-
-