Package org.apache.cassandra.concurrent
Class ThreadPoolExecutorBase
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- org.apache.cassandra.concurrent.ThreadPoolExecutorBase
-
- All Implemented Interfaces:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService,ResizableThreadPool
- Direct Known Subclasses:
ThreadPoolExecutorPlus
public class ThreadPoolExecutorBase extends java.util.concurrent.ThreadPoolExecutor implements ResizableThreadPool
This class incorporates some Executor best practices for Cassandra. Most of the executors in the system should use or extendThreadPoolExecutorPlus, or in rare exceptions this class. This class provides some very basic improvements:- We are configured by
ThreadPoolExecutorBuilder- Tasks rejected due to overflow of the queue block the submitting thread rather than throwing
RejectedExecutionExceptionRunnableFuturerejected due to executor shutdown will be cancelledRunnableFutureremoved byshutdownNow()will be cancelled We also provide a shutdown hook for JMX registration cleanup.
-
-
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
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.concurrent.RejectedExecutionHandlerblockingExecutionHandler
-
Constructor Summary
Constructors Constructor Description ThreadPoolExecutorBase(int threads, int keepAlive, java.util.concurrent.TimeUnit keepAliveUnits, java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, NamedThreadFactory threadFactory)ThreadPoolExecutorBase(ThreadPoolExecutorBuilder<?> builder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetActiveTaskCount()Returns the approximate number of threads that are actively executing tasks.intgetCoreThreads()intgetMaximumThreads()intgetPendingTaskCount()Returns the approximate total of tasks waiting to be executed.NamedThreadFactorygetThreadFactory()java.lang.RunnableonShutdown()voidonShutdown(java.lang.Runnable onShutdown)voidsetCoreThreads(int number)voidsetMaximumThreads(int number)voidshutdown()java.util.List<java.lang.Runnable>shutdownNow()protected voidterminated()java.lang.StringtoString()-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, execute, 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, newTaskFor, newTaskFor, submit, submit, submit
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.concurrent.ResizableThreadPool
getCompletedTaskCount, getCorePoolSize, getMaximumPoolSize, getMaxTasksQueued, oldestTaskQueueTime, setCorePoolSize, setMaximumPoolSize
-
-
-
-
Constructor Detail
-
ThreadPoolExecutorBase
public ThreadPoolExecutorBase(ThreadPoolExecutorBuilder<?> builder)
-
ThreadPoolExecutorBase
public ThreadPoolExecutorBase(int threads, int keepAlive, java.util.concurrent.TimeUnit keepAliveUnits, java.util.concurrent.BlockingQueue<java.lang.Runnable> queue, NamedThreadFactory threadFactory)
-
-
Method Detail
-
onShutdown
public void onShutdown(java.lang.Runnable onShutdown)
-
onShutdown
public java.lang.Runnable onShutdown()
-
terminated
protected void terminated()
- Overrides:
terminatedin classjava.util.concurrent.ThreadPoolExecutor
-
shutdown
public void shutdown()
- Specified by:
shutdownin interfacejava.util.concurrent.ExecutorService- Overrides:
shutdownin classjava.util.concurrent.ThreadPoolExecutor
-
shutdownNow
public java.util.List<java.lang.Runnable> shutdownNow()
- Specified by:
shutdownNowin interfacejava.util.concurrent.ExecutorService- Overrides:
shutdownNowin classjava.util.concurrent.ThreadPoolExecutor
-
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
-
getCoreThreads
public int getCoreThreads()
-
setCoreThreads
public void setCoreThreads(int number)
-
getMaximumThreads
public int getMaximumThreads()
-
setMaximumThreads
public void setMaximumThreads(int number)
-
getThreadFactory
public NamedThreadFactory getThreadFactory()
- Overrides:
getThreadFactoryin classjava.util.concurrent.ThreadPoolExecutor
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.concurrent.ThreadPoolExecutor
-
-