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.RejectedExecutionHandler
rejectedExecutionHandler
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(java.lang.Runnable run)
void
execute(WithResources withResources, java.lang.Runnable run)
Invoketask
.int
getActiveTaskCount()
Returns the approximate number of threads that are actively executing tasks.int
getCorePoolSize()
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).int
getMaximumPoolSize()
Returns maximum pool size of thread pool.int
getMaxTasksQueued()
int
getPendingTaskCount()
Returns the approximate total of tasks waiting to be executed.NamedThreadFactory
getThreadFactory()
boolean
inExecutor()
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)
void
setCorePoolSize(int number)
Allows user to resize minimum size of the thread pool.void
setMaximumPoolSize(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 CassandraFuture
Future<?>
submit(WithResources withResources, java.lang.Runnable run)
Invoketask
, returning a future yieldingnull
if successful, or the abnormal termination oftask
otherwise.<T> Future<T>
submit(WithResources withResources, java.lang.Runnable run, T result)
Invoketask
, returning a future yieldingresult
if successful, or the abnormal termination oftask
otherwise.<T> Future<T>
submit(WithResources withResources, java.util.concurrent.Callable<T> call)
Invoketask
, returning a future representing this computation.protected void
terminated()
-
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:
schedule
in interfacejava.util.concurrent.ScheduledExecutorService
- Overrides:
schedule
in 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:
schedule
in interfacejava.util.concurrent.ScheduledExecutorService
- Overrides:
schedule
in 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:
scheduleAtFixedRate
in interfacejava.util.concurrent.ScheduledExecutorService
- Overrides:
scheduleAtFixedRate
in 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:
scheduleWithFixedDelay
in interfacejava.util.concurrent.ScheduledExecutorService
- Overrides:
scheduleWithFixedDelay
in 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:ScheduledExecutorPlus
Schedule an action that is recurring but self-administered.- Specified by:
scheduleSelfRecurring
in interfaceScheduledExecutorPlus
-
scheduleAt
public java.util.concurrent.ScheduledFuture<?> scheduleAt(java.lang.Runnable run, long deadline)
Description copied from interface:ScheduledExecutorPlus
Schedule a timeout action. This method is primarily used by the Simulator to modify its scheduling behaviour with respect to this operation.- Specified by:
scheduleAt
in interfaceScheduledExecutorPlus
-
scheduleTimeoutAt
public java.util.concurrent.ScheduledFuture<?> scheduleTimeoutAt(java.lang.Runnable run, long deadline)
Description copied from interface:ScheduledExecutorPlus
Schedule a timeout action. This method is primarily used by the Simulator to modify its scheduling behaviour with respect to this operation.- Specified by:
scheduleTimeoutAt
in interfaceScheduledExecutorPlus
-
scheduleTimeoutWithDelay
public java.util.concurrent.ScheduledFuture<?> scheduleTimeoutWithDelay(java.lang.Runnable run, long delay, java.util.concurrent.TimeUnit units)
Description copied from interface:ScheduledExecutorPlus
Schedule a timeout action. This method is primarily used by the Simulator to modify its scheduling behaviour with respect to this operation.- Specified by:
scheduleTimeoutWithDelay
in interfaceScheduledExecutorPlus
-
execute
public void execute(java.lang.Runnable run)
- Specified by:
execute
in interfacejava.util.concurrent.Executor
- Overrides:
execute
in classjava.util.concurrent.ScheduledThreadPoolExecutor
-
execute
public void execute(WithResources withResources, java.lang.Runnable run)
Description copied from interface:ExecutorPlus
Invoketask
. 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:
execute
in interfaceExecutorPlus
- Parameters:
withResources
- the resources to create and hold while executingtask
run
- the task to execute
-
submit
public Future<?> submit(java.lang.Runnable run)
Description copied from interface:ExecutorPlus
OverridesExecutorService.submit(Runnable)
to return a CassandraFuture
- Specified by:
submit
in interfaceExecutorPlus
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Overrides:
submit
in classjava.util.concurrent.ScheduledThreadPoolExecutor
-
submit
public <T> Future<T> submit(java.lang.Runnable run, T result)
Description copied from interface:ExecutorPlus
OverridesExecutorService.submit(Runnable, Object)
to return a CassandraFuture
- Specified by:
submit
in interfaceExecutorPlus
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Overrides:
submit
in classjava.util.concurrent.ScheduledThreadPoolExecutor
-
submit
public <T> Future<T> submit(java.util.concurrent.Callable<T> call)
Description copied from interface:ExecutorPlus
OverridesExecutorService.submit(Callable)
to return a CassandraFuture
- Specified by:
submit
in interfaceExecutorPlus
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
- Overrides:
submit
in classjava.util.concurrent.ScheduledThreadPoolExecutor
-
submit
public <T> Future<T> submit(WithResources withResources, java.lang.Runnable run, T result)
Description copied from interface:ExecutorPlus
Invoketask
, returning a future yieldingresult
if successful, or the abnormal termination oftask
otherwise. 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:
submit
in interfaceExecutorPlus
- Parameters:
withResources
- the resources to create and hold while executingtask
run
- the task to executeresult
- the result if successful
-
submit
public Future<?> submit(WithResources withResources, java.lang.Runnable run)
Description copied from interface:ExecutorPlus
Invoketask
, returning a future yieldingnull
if successful, or the abnormal termination oftask
otherwise. 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:
submit
in interfaceExecutorPlus
- Parameters:
withResources
- the resources to create and hold while executingtask
run
- the task to execute
-
submit
public <T> Future<T> submit(WithResources withResources, java.util.concurrent.Callable<T> call)
Description copied from interface:ExecutorPlus
Invoketask
, 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:
submit
in interfaceExecutorPlus
- Parameters:
withResources
- the resources to create and hold while executingtask
call
- the task to execute
-
inExecutor
public boolean inExecutor()
- Specified by:
inExecutor
in 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:
newTaskFor
in classjava.util.concurrent.AbstractExecutorService
-
newTaskFor
protected <T> RunnableFuture<T> newTaskFor(java.util.concurrent.Callable<T> callable)
- Overrides:
newTaskFor
in classjava.util.concurrent.AbstractExecutorService
-
getThreadFactory
public NamedThreadFactory getThreadFactory()
- Overrides:
getThreadFactory
in classjava.util.concurrent.ThreadPoolExecutor
-
shutdownNow
public java.util.List<java.lang.Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfacejava.util.concurrent.ExecutorService
- Overrides:
shutdownNow
in classjava.util.concurrent.ScheduledThreadPoolExecutor
-
terminated
protected void terminated()
- Overrides:
terminated
in classjava.util.concurrent.ThreadPoolExecutor
-
getActiveTaskCount
public int getActiveTaskCount()
Description copied from interface:ResizableThreadPool
Returns the approximate number of threads that are actively executing tasks.- Specified by:
getActiveTaskCount
in interfaceResizableThreadPool
- Returns:
- the number of threads
-
getPendingTaskCount
public int getPendingTaskCount()
Description copied from interface:ResizableThreadPool
Returns 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:
getPendingTaskCount
in interfaceResizableThreadPool
- Returns:
- the number of tasks
-
getCorePoolSize
public int getCorePoolSize()
Description copied from interface:ResizableThreadPool
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).- Specified by:
getCorePoolSize
in interfaceResizableThreadPool
- Overrides:
getCorePoolSize
in classjava.util.concurrent.ThreadPoolExecutor
-
setCorePoolSize
public void setCorePoolSize(int number)
Description copied from interface:ResizableThreadPool
Allows user to resize minimum size of the thread pool.- Specified by:
setCorePoolSize
in interfaceResizableThreadPool
- Overrides:
setCorePoolSize
in classjava.util.concurrent.ThreadPoolExecutor
-
getMaximumPoolSize
public int getMaximumPoolSize()
Description copied from interface:ResizableThreadPool
Returns maximum pool size of thread pool.- Specified by:
getMaximumPoolSize
in interfaceResizableThreadPool
- Overrides:
getMaximumPoolSize
in classjava.util.concurrent.ThreadPoolExecutor
-
setMaximumPoolSize
public void setMaximumPoolSize(int number)
Description copied from interface:ResizableThreadPool
Allows user to resize maximum size of the thread pool.- Specified by:
setMaximumPoolSize
in interfaceResizableThreadPool
- Overrides:
setMaximumPoolSize
in classjava.util.concurrent.ThreadPoolExecutor
-
getMaxTasksQueued
public int getMaxTasksQueued()
- Specified by:
getMaxTasksQueued
in interfaceResizableThreadPool
-
-