Class EnhancedQueueExecutor.Builder

  • Enclosing class:
    EnhancedQueueExecutor

    public static final class EnhancedQueueExecutor.Builder
    extends Object
    The builder class for an EnhancedQueueExecutor. All the fields are initialized to sensible defaults for a small thread pool.
    • Constructor Detail

      • Builder

        public Builder()
        Construct a new instance.
    • Method Detail

      • getThreadFactory

        public ThreadFactory getThreadFactory()
        Get the configured thread factory.
        Returns:
        the configured thread factory (not null)
      • setThreadFactory

        public EnhancedQueueExecutor.Builder setThreadFactory​(ThreadFactory threadFactory)
        Set the configured thread factory.
        Parameters:
        threadFactory - the configured thread factory (must not be null)
        Returns:
        this builder
      • getTerminationTask

        public Runnable getTerminationTask()
        Get the termination task. By default, an empty Runnable is used.
        Returns:
        the termination task (not null)
      • setTerminationTask

        public EnhancedQueueExecutor.Builder setTerminationTask​(Runnable terminationTask)
        Set the termination task.
        Parameters:
        terminationTask - the termination task (must not be null)
        Returns:
        this builder
      • getCorePoolSize

        public int getCorePoolSize()
        Get the core pool size. This is the size below which new threads will always be created if no idle threads are available. If the pool size reaches the core size but has not yet reached the maximum size, a resistance factor will be applied to each task submission which determines whether the task should be queued or a new thread started.
        Returns:
        the core pool size
        See Also:
        EnhancedQueueExecutor.getCorePoolSize()
      • setCorePoolSize

        public EnhancedQueueExecutor.Builder setCorePoolSize​(int coreSize)
        Set the core pool size. If the configured maximum pool size is less than the configured core size, the core size will be reduced to match the maximum size when the thread pool is constructed.
        Parameters:
        coreSize - the core pool size (must be greater than or equal to 0, and less than 2^20)
        Returns:
        this builder
        See Also:
        EnhancedQueueExecutor.setCorePoolSize(int)
      • getMaximumPoolSize

        public int getMaximumPoolSize()
        Get the maximum pool size. This is the absolute upper limit to the size of the thread pool.
        Returns:
        the maximum pool size
        See Also:
        EnhancedQueueExecutor.getMaximumPoolSize()
      • setMaximumPoolSize

        public EnhancedQueueExecutor.Builder setMaximumPoolSize​(int maxSize)
        Set the maximum pool size. If the configured maximum pool size is less than the configured core size, the core size will be reduced to match the maximum size when the thread pool is constructed.
        Parameters:
        maxSize - the maximum pool size (must be greater than or equal to 0, and less than 2^20)
        Returns:
        this builder
        See Also:
        EnhancedQueueExecutor.setMaximumPoolSize(int)
      • getKeepAliveTime

        public Duration getKeepAliveTime()
        Get the thread keep-alive time. This is the amount of time (in the configured time unit) that idle threads will wait for a task before exiting.
        Returns:
        the thread keep-alive time duration
      • getKeepAliveTime

        @Deprecated
        public long getKeepAliveTime​(TimeUnit keepAliveUnits)
        Deprecated.
        Use getKeepAliveTime() instead.
        Get the thread keep-alive time. This is the amount of time (in the configured time unit) that idle threads will wait for a task before exiting.
        Parameters:
        keepAliveUnits - the time keepAliveUnits of the keep-alive time (must not be null)
        Returns:
        the thread keep-alive time
        See Also:
        EnhancedQueueExecutor.getKeepAliveTime(TimeUnit)
      • setKeepAliveTime

        public EnhancedQueueExecutor.Builder setKeepAliveTime​(Duration keepAliveTime)
        Set the thread keep-alive time.
        Parameters:
        keepAliveTime - the thread keep-alive time (must not be null)
      • getGrowthResistance

        public float getGrowthResistance()
        Get the thread pool growth resistance. This is the average fraction of submitted tasks that will be enqueued (instead of causing a new thread to start) when there are no idle threads and the pool size is equal to or greater than the core size (but still less than the maximum size). A value of 0.0 indicates that tasks should not be enqueued until the pool is completely full; a value of 1.0 indicates that tasks should always be enqueued until the queue is completely full.
        Returns:
        the thread pool growth resistance
        See Also:
        EnhancedQueueExecutor.getGrowthResistance()
      • allowsCoreThreadTimeOut

        public boolean allowsCoreThreadTimeOut()
        Determine whether core threads are allowed to time out. A "core thread" is defined as any thread in the pool when the pool size is below the pool's core pool size.
        Returns:
        true if core threads are allowed to time out, false otherwise
        See Also:
        EnhancedQueueExecutor.allowsCoreThreadTimeOut()
      • getMaximumQueueSize

        public int getMaximumQueueSize()
        Get the maximum queue size. If the queue is full and a task cannot be immediately accepted, rejection will result.
        Returns:
        the maximum queue size
        See Also:
        EnhancedQueueExecutor.getMaximumQueueSize()
      • getHandoffExecutor

        public Executor getHandoffExecutor()
        Get the handoff executor.
        Returns:
        the handoff executor (not null)
      • setHandoffExecutor

        public EnhancedQueueExecutor.Builder setHandoffExecutor​(Executor handoffExecutor)
        Set the handoff executor.
        Parameters:
        handoffExecutor - the handoff executor (must not be null)
        Returns:
        this builder
      • getExceptionHandler

        public Thread.UncaughtExceptionHandler getExceptionHandler()
        Get the uncaught exception handler.
        Returns:
        the uncaught exception handler (not null)
      • build

        public EnhancedQueueExecutor build()
        Construct the executor from the configured parameters.
        Returns:
        the executor, which will be active and ready to accept tasks (not null)
      • isRegisterMBean

        public boolean isRegisterMBean()
        Determine whether an MBean should automatically be registered for this pool.
        Returns:
        true if an MBean is to be auto-registered; false otherwise
      • setRegisterMBean

        public EnhancedQueueExecutor.Builder setRegisterMBean​(boolean registerMBean)
        Establish whether an MBean should automatically be registered for this pool.
        Parameters:
        registerMBean - true if an MBean is to be auto-registered; false otherwise
        Returns:
        this builder
      • getMBeanName

        public String getMBeanName()
        Get the overridden MBean name.
        Returns:
        the overridden MBean name, or null if a default name should be generated
      • setMBeanName

        public EnhancedQueueExecutor.Builder setMBeanName​(String mBeanName)
        Set the overridden MBean name.
        Parameters:
        mBeanName - the overridden MBean name, or null if a default name should be generated
        Returns:
        this builder