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:
Executor,ExecutorService,ExecutorPlus,ResizableThreadPool
- Direct Known Subclasses:
LocalAwareThreadPoolExecutorPlus,SingleThreadExecutorPlus
This class inherits Executor best practices from
ThreadPoolExecutorBase
and ThreadPoolExecutorBuilder. Most Cassandra executors should use or extend this.
This class' addition is to abstract the semantics of task encapsulation to handle
exceptions and ExecutorLocals. See TaskFactory for more detail.-
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 inherited from class org.apache.cassandra.concurrent.ThreadPoolExecutorBase
blockingExecutionHandler -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidexecute(WithResources withResources, Runnable run) Invoketask.intbooleanprotected <T> RunnableFuture<T>newTaskFor(Runnable runnable, T value) protected <T> RunnableFuture<T>newTaskFor(Callable<T> callable) 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.Methods inherited from class org.apache.cassandra.concurrent.ThreadPoolExecutorBase
getActiveTaskCount, getCoreThreads, getMaximumThreads, getPendingTaskCount, getThreadFactory, onShutdown, onShutdown, setCoreThreads, setMaximumThreads, shutdown, shutdownNow, terminated, toStringMethods 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, setThreadFactoryMethods 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, shutdown, shutdownNowMethods inherited from interface org.apache.cassandra.concurrent.ResizableThreadPool
getActiveTaskCount, getCompletedTaskCount, getCorePoolSize, getMaximumPoolSize, getPendingTaskCount, oldestTaskQueueTime, setCorePoolSize, setMaximumPoolSize
-
Method Details
-
execute
- Specified by:
executein interfaceExecutor- Overrides:
executein classThreadPoolExecutor
-
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 classAbstractExecutorService
-
submit
Description copied from interface:ExecutorPlusOverridesExecutorService.submit(Runnable, Object)to return a CassandraFuture- Specified by:
submitin interfaceExecutorPlus- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classAbstractExecutorService
-
submit
Description copied from interface:ExecutorPlusOverridesExecutorService.submit(Callable)to return a CassandraFuture- Specified by:
submitin interfaceExecutorPlus- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classAbstractExecutorService
-
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
-
getMaxTasksQueued
public int getMaxTasksQueued()- Specified by:
getMaxTasksQueuedin interfaceResizableThreadPool
-