Package org.apache.cassandra.concurrent
Class ThreadPoolExecutorPlus
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- org.apache.cassandra.concurrent.ThreadPoolExecutorBase
-
- org.apache.cassandra.concurrent.ThreadPoolExecutorPlus
-
- All Implemented Interfaces:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService,ExecutorPlus,ResizableThreadPool
- Direct Known Subclasses:
LocalAwareThreadPoolExecutorPlus,SingleThreadExecutorPlus
public class ThreadPoolExecutorPlus extends ThreadPoolExecutorBase implements ExecutorPlus
This class inherits Executor best practices fromThreadPoolExecutorBaseandThreadPoolExecutorBuilder. Most Cassandra executors should use or extend this. This class' addition is to abstract the semantics of task encapsulation to handle exceptions andExecutorLocals. SeeTaskFactoryfor more detail.
-
-
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 inherited from class org.apache.cassandra.concurrent.ThreadPoolExecutorBase
blockingExecutionHandler
-
-
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.intgetMaxTasksQueued()booleaninExecutor()protected <T> java.util.concurrent.RunnableFuture<T>newTaskFor(java.lang.Runnable runnable, T value)protected <T> java.util.concurrent.RunnableFuture<T>newTaskFor(java.util.concurrent.Callable<T> callable)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.-
Methods inherited from class org.apache.cassandra.concurrent.ThreadPoolExecutorBase
getActiveTaskCount, getCoreThreads, getMaximumThreads, getPendingTaskCount, getThreadFactory, onShutdown, onShutdown, setCoreThreads, setMaximumThreads, shutdown, shutdownNow, terminated, toString
-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory
-
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, shutdownNow
-
Methods inherited from interface org.apache.cassandra.concurrent.ResizableThreadPool
getActiveTaskCount, getCompletedTaskCount, getCorePoolSize, getMaximumPoolSize, getPendingTaskCount, oldestTaskQueueTime, setCorePoolSize, setMaximumPoolSize
-
-
-
-
Method Detail
-
execute
public void execute(java.lang.Runnable run)
- Specified by:
executein interfacejava.util.concurrent.Executor- Overrides:
executein classjava.util.concurrent.ThreadPoolExecutor
-
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.AbstractExecutorService
-
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.AbstractExecutorService
-
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.AbstractExecutorService
-
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> java.util.concurrent.RunnableFuture<T> newTaskFor(java.lang.Runnable runnable, T value)- Overrides:
newTaskForin classjava.util.concurrent.AbstractExecutorService
-
newTaskFor
protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor(java.util.concurrent.Callable<T> callable)
- Overrides:
newTaskForin classjava.util.concurrent.AbstractExecutorService
-
getMaxTasksQueued
public int getMaxTasksQueued()
- Specified by:
getMaxTasksQueuedin interfaceResizableThreadPool
-
-