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:
Executor,ExecutorService,ResizableThreadPool
- Direct Known Subclasses:
ThreadPoolExecutorPlus
This class incorporates some Executor best practices for Cassandra. Most of the executors in the system
should use or extend We are configured by Tasks rejected due to overflow of the queue block the submitting thread rather than throwing
ThreadPoolExecutorPlus, or in rare exceptions this class.
This class provides some very basic improvements:
ThreadPoolExecutorBuilder
RejectedExecutionException
RunnableFuture rejected due to executor shutdown will be cancelled
RunnableFuture removed by shutdownNow() 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
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionThreadPoolExecutorBase(int threads, int keepAlive, TimeUnit keepAliveUnits, BlockingQueue<Runnable> queue, NamedThreadFactory threadFactory) ThreadPoolExecutorBase(ThreadPoolExecutorBuilder<?> builder) -
Method Summary
Modifier and TypeMethodDescriptionintReturns the approximate number of threads that are actively executing tasks.intintintReturns the approximate total of tasks waiting to be executed.voidonShutdown(Runnable onShutdown) voidsetCoreThreads(int number) voidsetMaximumThreads(int number) voidshutdown()protected voidtoString()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, setThreadFactoryMethods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submitMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.cassandra.concurrent.ResizableThreadPool
getCompletedTaskCount, getCorePoolSize, getMaximumPoolSize, getMaxTasksQueued, oldestTaskQueueTime, setCorePoolSize, setMaximumPoolSize
-
Field Details
-
blockingExecutionHandler
-
-
Constructor Details
-
ThreadPoolExecutorBase
-
ThreadPoolExecutorBase
public ThreadPoolExecutorBase(int threads, int keepAlive, TimeUnit keepAliveUnits, BlockingQueue<Runnable> queue, NamedThreadFactory threadFactory)
-
-
Method Details
-
onShutdown
-
onShutdown
-
terminated
protected void terminated()- Overrides:
terminatedin classThreadPoolExecutor
-
shutdown
public void shutdown()- Specified by:
shutdownin interfaceExecutorService- Overrides:
shutdownin classThreadPoolExecutor
-
shutdownNow
- Specified by:
shutdownNowin interfaceExecutorService- Overrides:
shutdownNowin classThreadPoolExecutor
-
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
- Overrides:
getThreadFactoryin classThreadPoolExecutor
-
toString
- Overrides:
toStringin classThreadPoolExecutor
-