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:
Executor,ExecutorService,ScheduledExecutorService,ExecutorPlus,ResizableThreadPool,ScheduledExecutorPlus
public class ScheduledThreadPoolExecutorPlus
extends 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
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicyNested classes/interfaces inherited from interface org.apache.cassandra.concurrent.ExecutorPlus
ExecutorPlus.MaximumPoolSizeListener -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidexecute(WithResources withResources, Runnable run) Invoketask.intReturns the approximate number of threads that are actively executing tasks.intReturns 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).intReturns maximum pool size of thread pool.intintReturns the approximate total of tasks waiting to be executed.booleanprotected <T> RunnableFuture<T>newTaskFor(Runnable runnable, T value) protected <T> RunnableFuture<T>newTaskFor(Callable<T> callable) <V> ScheduledFuture<V>scheduleAt(Runnable run, long deadline) Schedule a timeout action.scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit unit) scheduleSelfRecurring(Runnable run, long delay, TimeUnit units) Schedule an action that is recurring but self-administered.scheduleTimeoutAt(Runnable run, long deadline) Schedule a timeout action.scheduleTimeoutWithDelay(Runnable run, long delay, TimeUnit units) Schedule a timeout action.scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, 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.Future<?>OverridesExecutorService.submit(Runnable)to return a CassandraFuture<T> Future<T>OverridesExecutorService.submit(Runnable, Object)to return a CassandraFuture<T> Future<T>OverridesExecutorService.submit(Callable)to return a CassandraFutureFuture<?>submit(WithResources withResources, Runnable run) Invoketask, returning a future yieldingnullif successful, or the abnormal termination oftaskotherwise.<T> Future<T>submit(WithResources withResources, Runnable run, T result) Invoketask, returning a future yieldingresultif successful, or the abnormal termination oftaskotherwise.<T> Future<T>submit(WithResources withResources, Callable<T> call) Invoketask, returning a future representing this computation.protected voidMethods inherited from class java.util.concurrent.ScheduledThreadPoolExecutor
decorateTask, decorateTask, getContinueExistingPeriodicTasksAfterShutdownPolicy, getExecuteExistingDelayedTasksAfterShutdownPolicy, getQueue, getRemoveOnCancelPolicy, setContinueExistingPeriodicTasksAfterShutdownPolicy, setExecuteExistingDelayedTasksAfterShutdownPolicy, setRemoveOnCancelPolicy, shutdownMethods 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, toStringMethods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAnyMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.cassandra.concurrent.ExecutorPlus
invokeAll, invokeAll, invokeAny, invokeAny, maybeExecuteImmediatelyMethods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, isShutdown, isTerminated, shutdownMethods inherited from interface org.apache.cassandra.concurrent.ResizableThreadPool
getCompletedTaskCount, oldestTaskQueueTime
-
Field Details
-
rejectedExecutionHandler
-
-
Method Details
-
schedule
- Specified by:
schedulein interfaceScheduledExecutorService- Overrides:
schedulein classScheduledThreadPoolExecutor
-
schedule
- Specified by:
schedulein interfaceScheduledExecutorService- Overrides:
schedulein classScheduledThreadPoolExecutor
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long initialDelay, long period, TimeUnit unit) - Specified by:
scheduleAtFixedRatein interfaceScheduledExecutorService- Overrides:
scheduleAtFixedRatein classScheduledThreadPoolExecutor
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit) - Specified by:
scheduleWithFixedDelayin interfaceScheduledExecutorService- Overrides:
scheduleWithFixedDelayin classScheduledThreadPoolExecutor
-
scheduleSelfRecurring
Description copied from interface:ScheduledExecutorPlusSchedule an action that is recurring but self-administered.- Specified by:
scheduleSelfRecurringin interfaceScheduledExecutorPlus
-
scheduleAt
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
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
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
- Specified by:
executein interfaceExecutor- Overrides:
executein classScheduledThreadPoolExecutor
-
execute
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
Description copied from interface:ExecutorPlusOverridesExecutorService.submit(Runnable)to return a CassandraFuture- Specified by:
submitin interfaceExecutorPlus- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classScheduledThreadPoolExecutor
-
submit
Description copied from interface:ExecutorPlusOverridesExecutorService.submit(Runnable, Object)to return a CassandraFuture- Specified by:
submitin interfaceExecutorPlus- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classScheduledThreadPoolExecutor
-
submit
Description copied from interface:ExecutorPlusOverridesExecutorService.submit(Callable)to return a CassandraFuture- Specified by:
submitin interfaceExecutorPlus- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classScheduledThreadPoolExecutor
-
submit
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
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
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
- Overrides:
newTaskForin classAbstractExecutorService
-
newTaskFor
- Overrides:
newTaskForin classAbstractExecutorService
-
getThreadFactory
- Overrides:
getThreadFactoryin classThreadPoolExecutor
-
shutdownNow
- Specified by:
shutdownNowin interfaceExecutorService- Overrides:
shutdownNowin classScheduledThreadPoolExecutor
-
terminated
protected void terminated()- Overrides:
terminatedin classThreadPoolExecutor
-
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 classThreadPoolExecutor
-
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 classThreadPoolExecutor
-
getMaximumPoolSize
public int getMaximumPoolSize()Description copied from interface:ResizableThreadPoolReturns maximum pool size of thread pool.- Specified by:
getMaximumPoolSizein interfaceResizableThreadPool- Overrides:
getMaximumPoolSizein classThreadPoolExecutor
-
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 classThreadPoolExecutor
-
getMaxTasksQueued
public int getMaxTasksQueued()- Specified by:
getMaxTasksQueuedin interfaceResizableThreadPool
-