Package org.apache.cassandra.concurrent
Class ScheduledThreadPoolExecutorPlus
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- java.util.concurrent.ScheduledThreadPoolExecutor
-
- org.apache.cassandra.concurrent.ScheduledThreadPoolExecutorPlus
-
- All Implemented Interfaces:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService,java.util.concurrent.ScheduledExecutorService,ExecutorPlus,ResizableThreadPool,ScheduledExecutorPlus
public class ScheduledThreadPoolExecutorPlus extends java.util.concurrent.ScheduledThreadPoolExecutor implements ScheduledExecutorPlus
Like ExecutorPlus, ScheduledThreadPoolExecutorPlus always logs exceptions from the tasks it is given, even if Future.get is never called elsewhere. Catches exceptions during Task execution so that they don't suppress subsequent invocations of the task. Finally, there is a special rejected execution handler for tasks rejected during the shutdown hook. - For fire and forget tasks (like ref tidy) we can safely ignore the exceptions. - For any callers that care to know their task was rejected we cancel passed task.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
-
Nested classes/interfaces inherited from interface org.apache.cassandra.concurrent.ExecutorPlus
ExecutorPlus.MaximumPoolSizeListener
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.concurrent.RejectedExecutionHandlerrejectedExecutionHandler
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexecute(java.lang.Runnable run)voidexecute(WithResources withResources, java.lang.Runnable run)Invoketask.intgetActiveTaskCount()Returns the approximate number of threads that are actively executing tasks.intgetCorePoolSize()Returns core pool size of thread pool, the minimum number of workers (where that makes sense for a thread pool, SEPExecutor does not have a minimum size).intgetMaximumPoolSize()Returns maximum pool size of thread pool.intgetMaxTasksQueued()intgetPendingTaskCount()Returns the approximate total of tasks waiting to be executed.NamedThreadFactorygetThreadFactory()booleaninExecutor()protected <T> RunnableFuture<T>newTaskFor(java.lang.Runnable runnable, T value)protected <T> RunnableFuture<T>newTaskFor(java.util.concurrent.Callable<T> callable)java.util.concurrent.ScheduledFuture<?>schedule(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit unit)<V> java.util.concurrent.ScheduledFuture<V>schedule(java.util.concurrent.Callable<V> task, long delay, java.util.concurrent.TimeUnit unit)java.util.concurrent.ScheduledFuture<?>scheduleAt(java.lang.Runnable run, long deadline)Schedule a timeout action.java.util.concurrent.ScheduledFuture<?>scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period, java.util.concurrent.TimeUnit unit)java.util.concurrent.ScheduledFuture<?>scheduleSelfRecurring(java.lang.Runnable run, long delay, java.util.concurrent.TimeUnit units)Schedule an action that is recurring but self-administered.java.util.concurrent.ScheduledFuture<?>scheduleTimeoutAt(java.lang.Runnable run, long deadline)Schedule a timeout action.java.util.concurrent.ScheduledFuture<?>scheduleTimeoutWithDelay(java.lang.Runnable run, long delay, java.util.concurrent.TimeUnit units)Schedule a timeout action.java.util.concurrent.ScheduledFuture<?>scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)voidsetCorePoolSize(int number)Allows user to resize minimum size of the thread pool.voidsetMaximumPoolSize(int number)Allows user to resize maximum size of the thread pool.java.util.List<java.lang.Runnable>shutdownNow()Future<?>submit(java.lang.Runnable run)OverridesExecutorService.submit(Runnable)to return a CassandraFuture<T> Future<T>submit(java.lang.Runnable run, T result)OverridesExecutorService.submit(Runnable, Object)to return a CassandraFuture<T> Future<T>submit(java.util.concurrent.Callable<T> call)OverridesExecutorService.submit(Callable)to return a CassandraFutureFuture<?>submit(WithResources withResources, java.lang.Runnable run)Invoketask, returning a future yieldingnullif successful, or the abnormal termination oftaskotherwise.<T> Future<T>submit(WithResources withResources, java.lang.Runnable run, T result)Invoketask, returning a future yieldingresultif successful, or the abnormal termination oftaskotherwise.<T> Future<T>submit(WithResources withResources, java.util.concurrent.Callable<T> call)Invoketask, returning a future representing this computation.protected voidterminated()-
Methods inherited from class java.util.concurrent.ScheduledThreadPoolExecutor
decorateTask, decorateTask, getContinueExistingPeriodicTasksAfterShutdownPolicy, getExecuteExistingDelayedTasksAfterShutdownPolicy, getQueue, getRemoveOnCancelPolicy, setContinueExistingPeriodicTasksAfterShutdownPolicy, setExecuteExistingDelayedTasksAfterShutdownPolicy, setRemoveOnCancelPolicy, shutdown
-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getKeepAliveTime, getLargestPoolSize, getPoolSize, getRejectedExecutionHandler, getTaskCount, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setKeepAliveTime, setRejectedExecutionHandler, setThreadFactory, toString
-
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.concurrent.ExecutorPlus
invokeAll, invokeAll, invokeAny, invokeAny, maybeExecuteImmediately
-
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, isShutdown, isTerminated, shutdown
-
Methods inherited from interface org.apache.cassandra.concurrent.ResizableThreadPool
getCompletedTaskCount, oldestTaskQueueTime
-
-
-
-
Method Detail
-
schedule
public java.util.concurrent.ScheduledFuture<?> schedule(java.lang.Runnable task, long delay, java.util.concurrent.TimeUnit unit)- Specified by:
schedulein interfacejava.util.concurrent.ScheduledExecutorService- Overrides:
schedulein classjava.util.concurrent.ScheduledThreadPoolExecutor
-
schedule
public <V> java.util.concurrent.ScheduledFuture<V> schedule(java.util.concurrent.Callable<V> task, long delay, java.util.concurrent.TimeUnit unit)- Specified by:
schedulein interfacejava.util.concurrent.ScheduledExecutorService- Overrides:
schedulein classjava.util.concurrent.ScheduledThreadPoolExecutor
-
scheduleAtFixedRate
public java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period, java.util.concurrent.TimeUnit unit)- Specified by:
scheduleAtFixedRatein interfacejava.util.concurrent.ScheduledExecutorService- Overrides:
scheduleAtFixedRatein classjava.util.concurrent.ScheduledThreadPoolExecutor
-
scheduleWithFixedDelay
public java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)- Specified by:
scheduleWithFixedDelayin interfacejava.util.concurrent.ScheduledExecutorService- Overrides:
scheduleWithFixedDelayin classjava.util.concurrent.ScheduledThreadPoolExecutor
-
scheduleSelfRecurring
public java.util.concurrent.ScheduledFuture<?> scheduleSelfRecurring(java.lang.Runnable run, long delay, java.util.concurrent.TimeUnit units)Description copied from interface:ScheduledExecutorPlusSchedule an action that is recurring but self-administered.- Specified by:
scheduleSelfRecurringin interfaceScheduledExecutorPlus
-
scheduleAt
public java.util.concurrent.ScheduledFuture<?> scheduleAt(java.lang.Runnable run, long deadline)Description copied from interface:ScheduledExecutorPlusSchedule a timeout action. This method is primarily used by the Simulator to modify its scheduling behaviour with respect to this operation.- Specified by:
scheduleAtin interfaceScheduledExecutorPlus
-
scheduleTimeoutAt
public java.util.concurrent.ScheduledFuture<?> scheduleTimeoutAt(java.lang.Runnable run, long deadline)Description copied from interface:ScheduledExecutorPlusSchedule a timeout action. This method is primarily used by the Simulator to modify its scheduling behaviour with respect to this operation.- Specified by:
scheduleTimeoutAtin interfaceScheduledExecutorPlus
-
scheduleTimeoutWithDelay
public java.util.concurrent.ScheduledFuture<?> scheduleTimeoutWithDelay(java.lang.Runnable run, long delay, java.util.concurrent.TimeUnit units)Description copied from interface:ScheduledExecutorPlusSchedule a timeout action. This method is primarily used by the Simulator to modify its scheduling behaviour with respect to this operation.- Specified by:
scheduleTimeoutWithDelayin interfaceScheduledExecutorPlus
-
execute
public void execute(java.lang.Runnable run)
- Specified by:
executein interfacejava.util.concurrent.Executor- Overrides:
executein classjava.util.concurrent.ScheduledThreadPoolExecutor
-
execute
public void execute(WithResources withResources, java.lang.Runnable run)
Description copied from interface:ExecutorPlusInvoketask. The invoking thread will first instantiate the resources provided before invokingtask, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to:try (Closeable close = withResources.get()) { task.run(); }- Specified by:
executein interfaceExecutorPlus- Parameters:
withResources- the resources to create and hold while executingtaskrun- the task to execute
-
submit
public Future<?> submit(java.lang.Runnable run)
Description copied from interface:ExecutorPlusOverridesExecutorService.submit(Runnable)to return a CassandraFuture- Specified by:
submitin interfaceExecutorPlus- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin classjava.util.concurrent.ScheduledThreadPoolExecutor
-
submit
public <T> Future<T> submit(java.lang.Runnable run, T result)
Description copied from interface:ExecutorPlusOverridesExecutorService.submit(Runnable, Object)to return a CassandraFuture- Specified by:
submitin interfaceExecutorPlus- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin classjava.util.concurrent.ScheduledThreadPoolExecutor
-
submit
public <T> Future<T> submit(java.util.concurrent.Callable<T> call)
Description copied from interface:ExecutorPlusOverridesExecutorService.submit(Callable)to return a CassandraFuture- Specified by:
submitin interfaceExecutorPlus- Specified by:
submitin interfacejava.util.concurrent.ExecutorService- Overrides:
submitin classjava.util.concurrent.ScheduledThreadPoolExecutor
-
submit
public <T> Future<T> submit(WithResources withResources, java.lang.Runnable run, T result)
Description copied from interface:ExecutorPlusInvoketask, returning a future yieldingresultif successful, or the abnormal termination oftaskotherwise. The invoking thread will first instantiate the resources provided before invokingtask, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to:try (Closeable close = withResources.get()) { task.run(); return result; }- Specified by:
submitin interfaceExecutorPlus- Parameters:
withResources- the resources to create and hold while executingtaskrun- the task to executeresult- the result if successful
-
submit
public Future<?> submit(WithResources withResources, java.lang.Runnable run)
Description copied from interface:ExecutorPlusInvoketask, returning a future yieldingnullif successful, or the abnormal termination oftaskotherwise. The invoking thread will first instantiate the resources provided before invokingtask, so that thread state may be modified and cleaned uptry (Closeable close = withResources.get()) { task.run(); return null; }- Specified by:
submitin interfaceExecutorPlus- Parameters:
withResources- the resources to create and hold while executingtaskrun- the task to execute
-
submit
public <T> Future<T> submit(WithResources withResources, java.util.concurrent.Callable<T> call)
Description copied from interface:ExecutorPlusInvoketask, returning a future representing this computation. The invoking thread will first instantiate the resources provided before invokingtask, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to:try (Closeable close = withResources.get()) { return task.call(); }- Specified by:
submitin interfaceExecutorPlus- Parameters:
withResources- the resources to create and hold while executingtaskcall- the task to execute
-
inExecutor
public boolean inExecutor()
- Specified by:
inExecutorin interfaceExecutorPlus- Returns:
- true iff the caller is a worker thread actively serving this executor
-
newTaskFor
protected <T> RunnableFuture<T> newTaskFor(java.lang.Runnable runnable, T value)
- Overrides:
newTaskForin classjava.util.concurrent.AbstractExecutorService
-
newTaskFor
protected <T> RunnableFuture<T> newTaskFor(java.util.concurrent.Callable<T> callable)
- Overrides:
newTaskForin classjava.util.concurrent.AbstractExecutorService
-
getThreadFactory
public NamedThreadFactory getThreadFactory()
- Overrides:
getThreadFactoryin classjava.util.concurrent.ThreadPoolExecutor
-
shutdownNow
public java.util.List<java.lang.Runnable> shutdownNow()
- Specified by:
shutdownNowin interfacejava.util.concurrent.ExecutorService- Overrides:
shutdownNowin classjava.util.concurrent.ScheduledThreadPoolExecutor
-
terminated
protected void terminated()
- Overrides:
terminatedin classjava.util.concurrent.ThreadPoolExecutor
-
getActiveTaskCount
public int getActiveTaskCount()
Description copied from interface:ResizableThreadPoolReturns the approximate number of threads that are actively executing tasks.- Specified by:
getActiveTaskCountin interfaceResizableThreadPool- Returns:
- the number of threads
-
getPendingTaskCount
public int getPendingTaskCount()
Description copied from interface:ResizableThreadPoolReturns the approximate total of tasks waiting to be executed. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation.- Specified by:
getPendingTaskCountin interfaceResizableThreadPool- Returns:
- the number of tasks
-
getCorePoolSize
public int getCorePoolSize()
Description copied from interface:ResizableThreadPoolReturns core pool size of thread pool, the minimum number of workers (where that makes sense for a thread pool, SEPExecutor does not have a minimum size).- Specified by:
getCorePoolSizein interfaceResizableThreadPool- Overrides:
getCorePoolSizein classjava.util.concurrent.ThreadPoolExecutor
-
setCorePoolSize
public void setCorePoolSize(int number)
Description copied from interface:ResizableThreadPoolAllows user to resize minimum size of the thread pool.- Specified by:
setCorePoolSizein interfaceResizableThreadPool- Overrides:
setCorePoolSizein classjava.util.concurrent.ThreadPoolExecutor
-
getMaximumPoolSize
public int getMaximumPoolSize()
Description copied from interface:ResizableThreadPoolReturns maximum pool size of thread pool.- Specified by:
getMaximumPoolSizein interfaceResizableThreadPool- Overrides:
getMaximumPoolSizein classjava.util.concurrent.ThreadPoolExecutor
-
setMaximumPoolSize
public void setMaximumPoolSize(int number)
Description copied from interface:ResizableThreadPoolAllows user to resize maximum size of the thread pool.- Specified by:
setMaximumPoolSizein interfaceResizableThreadPool- Overrides:
setMaximumPoolSizein classjava.util.concurrent.ThreadPoolExecutor
-
getMaxTasksQueued
public int getMaxTasksQueued()
- Specified by:
getMaxTasksQueuedin interfaceResizableThreadPool
-
-