类 ThreadPoolBuilder


  • public class ThreadPoolBuilder
    extends java.lang.Object
    For building ThreadPoolExecutor.
    • 方法详细资料

      • 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 0
        maxPoolSize - 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 using Executor.execute(Runnable), exception will be handler by
        • Thread's ExceptionHandler if exits;
        • ThreadGroup's ExceptionHandler if exists;
        • The default ExceptionHandler
        If noting is set, the default handler will stop the thread, and print exception.

        If the task is submit using ExecutorService.submit(Runnable), or ExecutorService.submit(Callable), The exception will be caught and set to Future, the thread is leaved unaffected.
        参数:
        listener - the exception listener
        返回:
        self