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
RejectedExecutionException
RunnableFuture
rejected due to executor shutdown will be cancelledRunnableFuture
removed 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.RejectedExecutionHandler
blockingExecutionHandler
-
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 int
getActiveTaskCount()
Returns the approximate number of threads that are actively executing tasks.int
getCoreThreads()
int
getMaximumThreads()
int
getPendingTaskCount()
Returns the approximate total of tasks waiting to be executed.NamedThreadFactory
getThreadFactory()
java.lang.Runnable
onShutdown()
void
onShutdown(java.lang.Runnable onShutdown)
void
setCoreThreads(int number)
void
setMaximumThreads(int number)
void
shutdown()
java.util.List<java.lang.Runnable>
shutdownNow()
protected void
terminated()
java.lang.String
toString()
-
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:
terminated
in classjava.util.concurrent.ThreadPoolExecutor
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfacejava.util.concurrent.ExecutorService
- Overrides:
shutdown
in classjava.util.concurrent.ThreadPoolExecutor
-
shutdownNow
public java.util.List<java.lang.Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfacejava.util.concurrent.ExecutorService
- Overrides:
shutdownNow
in classjava.util.concurrent.ThreadPoolExecutor
-
getActiveTaskCount
public int getActiveTaskCount()
Description copied from interface:ResizableThreadPool
Returns the approximate number of threads that are actively executing tasks.- Specified by:
getActiveTaskCount
in interfaceResizableThreadPool
- Returns:
- the number of threads
-
getPendingTaskCount
public int getPendingTaskCount()
Description copied from interface:ResizableThreadPool
Returns 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:
getPendingTaskCount
in 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:
getThreadFactory
in classjava.util.concurrent.ThreadPoolExecutor
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.concurrent.ThreadPoolExecutor
-
-