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
keepAlivetime inkeepAliveUnits- Threads share the same
ThreadGroup, which may be configurably a child of a specifiedThreadGroupdescended from the same parent of theNamedThreadFactory.MetaFactory- By default queues are unbounded in length
- The default
RejectedExecutionHandleris implementation dependent, but may be overridden- The default
Thread.UncaughtExceptionHandleris 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 protectedThreadPoolExecutorBuilder(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 Ebuild()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 theRejectedExecutionHandlerfor 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.UncaughtExceptionHandlerfor 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:ExecutorBuilderThreads for the executor built by this factory will timeout (terminate) after the specified period.- Specified by:
withKeepAlivein interfaceExecutorBuilder<E extends ExecutorPlus>
-
withKeepAlive
public ThreadPoolExecutorBuilder<E> withKeepAlive()
Description copied from interface:ExecutorBuilderCore 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:
withKeepAlivein interfaceExecutorBuilder<E extends ExecutorPlus>
-
withThreadPriority
public ThreadPoolExecutorBuilder<E> withThreadPriority(int threadPriority)
Description copied from interface:ExecutorBuilderSpecify the priority of threads that service the executor built by this factory (default toThread.NORM_PRIORITY)- Specified by:
withThreadPriorityin interfaceExecutorBuilder<E extends ExecutorPlus>
-
withThreadGroup
public ExecutorBuilder<E> withThreadGroup(java.lang.ThreadGroup threadGroup)
Description copied from interface:ExecutorBuilderThreads for the executor built by this factory will all be (transitively) members ofthreadGroup, but may directly reside in a child thread group.- Specified by:
withThreadGroupin interfaceExecutorBuilder<E extends ExecutorPlus>
-
withDefaultThreadGroup
public ExecutorBuilder<E> withDefaultThreadGroup()
Description copied from interface:ExecutorBuilderUse 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:
withDefaultThreadGroupin interfaceExecutorBuilder<E extends ExecutorPlus>
-
withQueueLimit
public ThreadPoolExecutorBuilder<E> withQueueLimit(int queueLimit)
Description copied from interface:ExecutorBuilderThe 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:
withQueueLimitin interfaceExecutorBuilder<E extends ExecutorPlus>
-
withRejectedExecutionHandler
public ThreadPoolExecutorBuilder<E> withRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler rejectedExecutionHandler)
Description copied from interface:ExecutorBuilderSet theRejectedExecutionHandlerfor the executor built by this factory. By default this is executor-specific, either:ThreadPoolExecutorBase.blockingExecutionHandlerScheduledThreadPoolExecutorPlus.rejectedExecutionHandler- and maybe wrapped by
ThreadPoolExecutorJMXAdapter.rejectedExecutionHandler(org.apache.cassandra.metrics.ThreadPoolMetrics, java.util.concurrent.RejectedExecutionHandler)- Specified by:
withRejectedExecutionHandlerin interfaceExecutorBuilder<E extends ExecutorPlus>
-
withUncaughtExceptionHandler
public ThreadPoolExecutorBuilder<E> withUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler)
Description copied from interface:ExecutorBuilderSet theThread.UncaughtExceptionHandlerfor threads that service executors built by this factory. By defaultJVMStabilityInspector.uncaughtException(Thread, Throwable)- Specified by:
withUncaughtExceptionHandlerin interfaceExecutorBuilder<E extends ExecutorPlus>
-
build
public E build()
Description copied from interface:ExecutorBuilderBuild the configured executor- Specified by:
buildin interfaceExecutorBuilder<E extends ExecutorPlus>
-
-