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 fromThreadPoolExecutorBase
andThreadPoolExecutorBuilder
. Most Cassandra executors should use or extend this. This class' addition is to abstract the semantics of task encapsulation to handle exceptions andExecutorLocals
. SeeTaskFactory
for 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 void
execute(java.lang.Runnable run)
void
execute(WithResources withResources, java.lang.Runnable run)
Invoketask
.int
getMaxTasksQueued()
boolean
inExecutor()
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 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.-
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:
execute
in interfacejava.util.concurrent.Executor
- Overrides:
execute
in classjava.util.concurrent.ThreadPoolExecutor
-
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.AbstractExecutorService
-
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.AbstractExecutorService
-
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.AbstractExecutorService
-
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> java.util.concurrent.RunnableFuture<T> newTaskFor(java.lang.Runnable runnable, T value)
- Overrides:
newTaskFor
in classjava.util.concurrent.AbstractExecutorService
-
newTaskFor
protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor(java.util.concurrent.Callable<T> callable)
- Overrides:
newTaskFor
in classjava.util.concurrent.AbstractExecutorService
-
getMaxTasksQueued
public int getMaxTasksQueued()
- Specified by:
getMaxTasksQueued
in interfaceResizableThreadPool
-
-