类 ThreadPoolBuilder
- java.lang.Object
-
- net.dongliu.commons.concurrent.ThreadPoolBuilder
-
public class ThreadPoolBuilder extends java.lang.ObjectFor building ThreadPoolExecutor.
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 static interfaceThreadPoolBuilder.TaskExceptionListenerListener that receive the exception of failed task.
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ThreadPoolBuilderallowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)If true, core threads use keepAliveTime to time out waiting for work.java.util.concurrent.ThreadPoolExecutorbuild()Build ThreadPoolExecutorThreadPoolBuilderkeepAliveTime(java.time.Duration keepAliveTime)Time to keep thread when thread count max than corePoolSize.ThreadPoolBuilderpoolSize(int corePoolSize, int maxPoolSize)Set corePoolSize and maxPoolSize.ThreadPoolBuilderrejectedHandler(java.util.concurrent.RejectedExecutionHandler rejectedHandler)Provide Reject Handler. default use ThreadPoolExecutor.AbortPolicy.ThreadPoolBuildertaskExceptionListener(ThreadPoolBuilder.TaskExceptionListener listener)Set Exception listener for this thread pool.ThreadPoolBuilderthreadFactory(java.util.concurrent.ThreadFactory threadFactory)Provide threadFactory.ThreadPoolBuilderworkingQueue(java.util.concurrent.BlockingQueue<java.lang.Runnable> workingQueue)Provide working Queue.
-
-
-
方法详细资料
-
build
public java.util.concurrent.ThreadPoolExecutor build()
Build ThreadPoolExecutor- 返回:
- the ThreadPoolExecutor
-
poolSize
public ThreadPoolBuilder poolSize(int corePoolSize, int maxPoolSize)
Set corePoolSize and maxPoolSize.- 参数:
corePoolSize- default 0maxPoolSize- default Integer.MAX_VALUE- 返回:
- self
-
keepAliveTime
public ThreadPoolBuilder keepAliveTime(java.time.Duration keepAliveTime)
Time to keep thread when thread count max than corePoolSize. Default 30 seconds.- 参数:
keepAliveTime- the keep alive time- 返回:
- self
-
workingQueue
public ThreadPoolBuilder workingQueue(java.util.concurrent.BlockingQueue<java.lang.Runnable> workingQueue)
Provide working Queue. Default use unlimited LinkedBlockingQueue.- 参数:
workingQueue- the workingQueue for thread pool- 返回:
- self
-
threadFactory
public ThreadPoolBuilder threadFactory(java.util.concurrent.ThreadFactory threadFactory)
Provide threadFactory. Default use NamedThreadFactory.- 参数:
threadFactory- the threadFactory- 返回:
- self
-
rejectedHandler
public ThreadPoolBuilder rejectedHandler(java.util.concurrent.RejectedExecutionHandler rejectedHandler)
Provide Reject Handler. default use ThreadPoolExecutor.AbortPolicy.- 参数:
rejectedHandler- the Reject Handler- 返回:
- self
-
allowCoreThreadTimeOut
public ThreadPoolBuilder allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
If true, core threads use keepAliveTime to time out waiting for work. Default false
-
taskExceptionListener
public ThreadPoolBuilder taskExceptionListener(ThreadPoolBuilder.TaskExceptionListener listener)
Set Exception listener for this thread pool. Note that this do not change the exception handler of the ThreadPool, or the Thread that run the task. If If the task is submit usingExecutor.execute(Runnable), exception will be handler by- Thread's ExceptionHandler if exits;
- ThreadGroup's ExceptionHandler if exists;
- The default ExceptionHandler
ExecutorService.submit(Runnable), orExecutorService.submit(Callable), The exception will be caught and set to Future, the thread is leaved unaffected.- 参数:
listener- the exception listener- 返回:
- self
-
-