类 ThreadPoolTaskExecutor

    • 方法详细资料

      • setCorePoolSize

        public void setCorePoolSize​(int corePoolSize)
        Set the ThreadPoolExecutor's core pool size. Default is 1.

        This setting can be modified at runtime, for example through JMX.

      • getCorePoolSize

        public int getCorePoolSize()
        Return the ThreadPoolExecutor's core pool size.
      • setMaxPoolSize

        public void setMaxPoolSize​(int maxPoolSize)
        Set the ThreadPoolExecutor's maximum pool size. Default is Integer.MAX_VALUE.

        This setting can be modified at runtime, for example through JMX.

      • getMaxPoolSize

        public int getMaxPoolSize()
        Return the ThreadPoolExecutor's maximum pool size.
      • setKeepAliveSeconds

        public void setKeepAliveSeconds​(int keepAliveSeconds)
        Set the ThreadPoolExecutor's keep-alive seconds. Default is 60.

        This setting can be modified at runtime, for example through JMX.

      • getKeepAliveSeconds

        public int getKeepAliveSeconds()
        Return the ThreadPoolExecutor's keep-alive seconds.
      • setQueueCapacity

        public void setQueueCapacity​(int queueCapacity)
        Set the capacity for the ThreadPoolExecutor's BlockingQueue. Default is Integer.MAX_VALUE.

        Any positive value will lead to a LinkedBlockingQueue instance; any other value will lead to a SynchronousQueue instance.

        另请参阅:
        LinkedBlockingQueue, SynchronousQueue
      • setAllowCoreThreadTimeOut

        public void setAllowCoreThreadTimeOut​(boolean allowCoreThreadTimeOut)
        Specify whether to allow core threads to time out. This enables dynamic growing and shrinking even in combination with a non-zero queue (since the max pool size will only grow once the queue is full).

        Default is "false".

        另请参阅:
        ThreadPoolExecutor.allowCoreThreadTimeOut(boolean)
      • setTaskDecorator

        public void setTaskDecorator​(TaskDecorator taskDecorator)
        Specify a custom TaskDecorator to be applied to any Runnable about to be executed.

        Note that such a decorator is not necessarily being applied to the user-supplied Runnable/Callable but rather to the actual execution callback (which may be a wrapper around the user-supplied task).

        The primary use case is to set some execution context around the task's invocation, or to provide some monitoring/statistics for task execution.

        NOTE: Exception handling in TaskDecorator implementations is limited to plain Runnable execution via execute calls. In case of #submit calls, the exposed Runnable will be a FutureTask which does not propagate any exceptions; you might have to cast it and call Future#get to evaluate exceptions. See the ThreadPoolExecutor#afterExecute javadoc for an example of how to access exceptions in such a Future case.

        从以下版本开始:
        4.3
      • createQueue

        protected BlockingQueue<RunnablecreateQueue​(int queueCapacity)
        Create the BlockingQueue to use for the ThreadPoolExecutor.

        A LinkedBlockingQueue instance will be created for a positive capacity value; a SynchronousQueue else.

        参数:
        queueCapacity - the specified queue capacity
        返回:
        the BlockingQueue instance
        另请参阅:
        LinkedBlockingQueue, SynchronousQueue
      • execute

        public void execute​(Runnable task)
        从接口复制的说明: TaskExecutor
        Execute the given task.

        The call might return immediately if the implementation uses an asynchronous execution strategy, or might block in the case of synchronous execution.

        指定者:
        execute 在接口中 Executor
        指定者:
        execute 在接口中 TaskExecutor
        参数:
        task - the Runnable to execute (never null)
      • submit

        public Future<?> submit​(Runnable task)
        从接口复制的说明: AsyncTaskExecutor
        Submit a Runnable task for execution, receiving a Future representing that task. The Future will return a null result upon completion.
        指定者:
        submit 在接口中 AsyncTaskExecutor
        参数:
        task - the Runnable to execute (never null)
        返回:
        a Future representing pending completion of the task
      • submit

        public <T> Future<T> submit​(Callable<T> task)
        从接口复制的说明: AsyncTaskExecutor
        Submit a Callable task for execution, receiving a Future representing that task. The Future will return the Callable's result upon completion.
        指定者:
        submit 在接口中 AsyncTaskExecutor
        参数:
        task - the Callable to execute (never null)
        返回:
        a Future representing pending completion of the task