Package io.pravega.common.concurrent
Class ThreadPoolScheduledExecutorService
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- io.pravega.common.concurrent.ThreadPoolScheduledExecutorService
-
- All Implemented Interfaces:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService,java.util.concurrent.ScheduledExecutorService
public class ThreadPoolScheduledExecutorService extends java.util.concurrent.AbstractExecutorService implements java.util.concurrent.ScheduledExecutorServiceAn implementation ofScheduledExecutorServicewhich uses a thread pool. This class is similar to ScheduledThreadPoolExecutor but differs in the following ways: 1. The thread pool supports growing. IE:maxPoolSizeandcorePoolSizedon't have to be the same. 2. Queued tasks are stored in a lock-free queue so that no bottlenecks can occur on submit. 3. Scheduling a task without a delay is O(1) as opposed to O(log(n)) 4. Canceling a task actually removes it from the queue and is O(n) as opposed to a no-op which leaves it in the queue or O(log(n)) whensetRemoveOnCancelPolicy(true). 5. ThemayInteruptIfRunningflag on cancel is ignored and assumed to be false. 6.ContinueExistingPeriodicTasksAfterShutdownandExecuteExistingDelayedTasksAfterShutdownare always false.
-
-
Constructor Summary
Constructors Constructor Description ThreadPoolScheduledExecutorService(int corePoolSize, java.util.concurrent.ThreadFactory threadFactory)Creates a fixed size thread pool (Similar to ScheduledThreadPoolExecutor).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitTermination(long timeout, java.util.concurrent.TimeUnit unit)voidexecute(java.lang.Runnable command)booleanisShutdown()booleanisTerminated()java.util.concurrent.ScheduledFuture<?>schedule(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)<V> java.util.concurrent.ScheduledFuture<V>schedule(java.util.concurrent.Callable<V> callable, long delay, java.util.concurrent.TimeUnit unit)java.util.concurrent.ScheduledFuture<?>scheduleAtFixedRate(java.lang.Runnable command, long initialDelay, long period, java.util.concurrent.TimeUnit unit)java.util.concurrent.ScheduledFuture<?>scheduleWithFixedDelay(java.lang.Runnable command, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)voidshutdown()java.util.List<java.lang.Runnable>shutdownNow()java.lang.StringtoString()-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
-
-
-
Constructor Detail
-
ThreadPoolScheduledExecutorService
public ThreadPoolScheduledExecutorService(int corePoolSize, java.util.concurrent.ThreadFactory threadFactory)Creates a fixed size thread pool (Similar to ScheduledThreadPoolExecutor).- Parameters:
corePoolSize- The number of threads in the poolthreadFactory- The factory used to create the threads.
-
-
Method Detail
-
shutdown
public void shutdown()
- Specified by:
shutdownin interfacejava.util.concurrent.ExecutorService
-
shutdownNow
public java.util.List<java.lang.Runnable> shutdownNow()
- Specified by:
shutdownNowin interfacejava.util.concurrent.ExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdownin interfacejava.util.concurrent.ExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminatedin interfacejava.util.concurrent.ExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Specified by:
awaitTerminationin interfacejava.util.concurrent.ExecutorService- Throws:
java.lang.InterruptedException
-
execute
public void execute(java.lang.Runnable command)
- Specified by:
executein interfacejava.util.concurrent.Executor
-
schedule
public java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable command, long delay, java.util.concurrent.TimeUnit unit)- Specified by:
schedulein interfacejava.util.concurrent.ScheduledExecutorService
-
schedule
public <V> java.util.concurrent.ScheduledFuture<V> schedule(java.util.concurrent.Callable<V> callable, long delay, java.util.concurrent.TimeUnit unit)- Specified by:
schedulein interfacejava.util.concurrent.ScheduledExecutorService
-
scheduleAtFixedRate
public java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable command, long initialDelay, long period, java.util.concurrent.TimeUnit unit)- Specified by:
scheduleAtFixedRatein interfacejava.util.concurrent.ScheduledExecutorService
-
scheduleWithFixedDelay
public java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable command, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)- Specified by:
scheduleWithFixedDelayin interfacejava.util.concurrent.ScheduledExecutorService
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-