Package org.apache.cassandra.concurrent
Class ThreadPoolExecutorBuilder<E extends ExecutorPlus>
- java.lang.Object
-
- org.apache.cassandra.concurrent.NamedThreadFactory.MetaFactory
-
- org.apache.cassandra.concurrent.ThreadPoolExecutorBuilder<E>
-
- All Implemented Interfaces:
ExecutorBuilder<E>
public class ThreadPoolExecutorBuilder<E extends ExecutorPlus> extends NamedThreadFactory.MetaFactory implements ExecutorBuilder<E>
Configure aThreadPoolExecutorPlus
, applying Cassandra's best practices by default- Core threads may timeout, and use a default
keepAlive
time inkeepAliveUnits
- Threads share the same
ThreadGroup
, which may be configurably a child of a specifiedThreadGroup
descended from the same parent of theNamedThreadFactory.MetaFactory
- By default queues are unbounded in length
- The default
RejectedExecutionHandler
is implementation dependent, but may be overridden- The default
Thread.UncaughtExceptionHandler
is inherited fromNamedThreadFactory.MetaFactory
, which in turn receives it from theExecutorBuilderFactory
-
-
Field Summary
-
Fields inherited from class org.apache.cassandra.concurrent.NamedThreadFactory.MetaFactory
contextClassLoader, threadGroup, uncaughtExceptionHandler
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ThreadPoolExecutorBuilder(java.util.function.Function<ThreadPoolExecutorBuilder<E>,E> constructor, java.lang.ClassLoader contextClassLoader, java.lang.ThreadGroup overrideThreadGroup, java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler, java.lang.String name, int threads)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description E
build()
Build the configured executorExecutorBuilder<E>
withDefaultThreadGroup()
Use the system default thread group for the threads we create.ThreadPoolExecutorBuilder<E>
withKeepAlive()
Core threads for the executor built by this factory will never timeout (default for single threaded builders).ThreadPoolExecutorBuilder<E>
withKeepAlive(long keepAlive, java.util.concurrent.TimeUnit keepAliveUnits)
Threads for the executor built by this factory will timeout (terminate) after the specified period.ThreadPoolExecutorBuilder<E>
withQueueLimit(int queueLimit)
The executor built by this factory will limit the number of queued tasks; default is unlimited.ThreadPoolExecutorBuilder<E>
withRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
Set theRejectedExecutionHandler
for the executor built by this factory.ExecutorBuilder<E>
withThreadGroup(java.lang.ThreadGroup threadGroup)
Threads for the executor built by this factory will all be (transitively) members ofthreadGroup
, but may directly reside in a child thread group.ThreadPoolExecutorBuilder<E>
withThreadPriority(int threadPriority)
Specify the priority of threads that service the executor built by this factory (default toThread.NORM_PRIORITY
)ThreadPoolExecutorBuilder<E>
withUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler)
Set theThread.UncaughtExceptionHandler
for threads that service executors built by this factory.
-
-
-
Constructor Detail
-
ThreadPoolExecutorBuilder
protected ThreadPoolExecutorBuilder(java.util.function.Function<ThreadPoolExecutorBuilder<E>,E> constructor, java.lang.ClassLoader contextClassLoader, java.lang.ThreadGroup overrideThreadGroup, java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler, java.lang.String name, int threads)
-
-
Method Detail
-
withKeepAlive
public ThreadPoolExecutorBuilder<E> withKeepAlive(long keepAlive, java.util.concurrent.TimeUnit keepAliveUnits)
Description copied from interface:ExecutorBuilder
Threads for the executor built by this factory will timeout (terminate) after the specified period.- Specified by:
withKeepAlive
in interfaceExecutorBuilder<E extends ExecutorPlus>
-
withKeepAlive
public ThreadPoolExecutorBuilder<E> withKeepAlive()
Description copied from interface:ExecutorBuilder
Core threads for the executor built by this factory will never timeout (default for single threaded builders). Note that there is ordinarily no difference between core and non-core threads; only when the queue limit is zero do we create non-core threads.- Specified by:
withKeepAlive
in interfaceExecutorBuilder<E extends ExecutorPlus>
-
withThreadPriority
public ThreadPoolExecutorBuilder<E> withThreadPriority(int threadPriority)
Description copied from interface:ExecutorBuilder
Specify the priority of threads that service the executor built by this factory (default toThread.NORM_PRIORITY
)- Specified by:
withThreadPriority
in interfaceExecutorBuilder<E extends ExecutorPlus>
-
withThreadGroup
public ExecutorBuilder<E> withThreadGroup(java.lang.ThreadGroup threadGroup)
Description copied from interface:ExecutorBuilder
Threads for the executor built by this factory will all be (transitively) members ofthreadGroup
, but may directly reside in a child thread group.- Specified by:
withThreadGroup
in interfaceExecutorBuilder<E extends ExecutorPlus>
-
withDefaultThreadGroup
public ExecutorBuilder<E> withDefaultThreadGroup()
Description copied from interface:ExecutorBuilder
Use the system default thread group for the threads we create. This is used only for testing, so that we do not hold onto a transitive global reference to all threads.- Specified by:
withDefaultThreadGroup
in interfaceExecutorBuilder<E extends ExecutorPlus>
-
withQueueLimit
public ThreadPoolExecutorBuilder<E> withQueueLimit(int queueLimit)
Description copied from interface:ExecutorBuilder
The executor built by this factory will limit the number of queued tasks; default is unlimited. Once the queue limit is reached and all threads are executing tasks will be rejected (seeExecutorBuilder.withRejectedExecutionHandler(RejectedExecutionHandler)
)- Specified by:
withQueueLimit
in interfaceExecutorBuilder<E extends ExecutorPlus>
-
withRejectedExecutionHandler
public ThreadPoolExecutorBuilder<E> withRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
Description copied from interface:ExecutorBuilder
Set theRejectedExecutionHandler
for the executor built by this factory. By default this is executor-specific, either:ThreadPoolExecutorBase.blockingExecutionHandler
ScheduledThreadPoolExecutorPlus.rejectedExecutionHandler
- and maybe wrapped by
ThreadPoolExecutorJMXAdapter.rejectedExecutionHandler(org.apache.cassandra.metrics.ThreadPoolMetrics, java.util.concurrent.RejectedExecutionHandler)
- Specified by:
withRejectedExecutionHandler
in interfaceExecutorBuilder<E extends ExecutorPlus>
-
withUncaughtExceptionHandler
public ThreadPoolExecutorBuilder<E> withUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler)
Description copied from interface:ExecutorBuilder
Set theThread.UncaughtExceptionHandler
for threads that service executors built by this factory. By defaultJVMStabilityInspector.uncaughtException(Thread, Throwable)
- Specified by:
withUncaughtExceptionHandler
in interfaceExecutorBuilder<E extends ExecutorPlus>
-
build
public E build()
Description copied from interface:ExecutorBuilder
Build the configured executor- Specified by:
build
in interfaceExecutorBuilder<E extends ExecutorPlus>
-
-