Class VirtualThreadPoolTaskExecutor

All Implemented Interfaces:
Serializable, Executor, ThreadFactory, EventListener, Aware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, ApplicationListener<ContextClosedEvent>, Lifecycle, Phased, SmartLifecycle, AsyncTaskExecutor, TaskExecutor, SchedulingTaskExecutor

public class VirtualThreadPoolTaskExecutor extends ExecutorConfigurationSupport implements AsyncTaskExecutor, SchedulingTaskExecutor
See Also:
  • Constructor Details

    • VirtualThreadPoolTaskExecutor

      public VirtualThreadPoolTaskExecutor()
  • Method Details

    • setPoolSize

      public void setPoolSize(int poolSize)
      Set the the maximum number of managed threads.
      Parameters:
      poolSize - the value to set (default is Integer.MAX_VALUE)
    • getPoolSize

      public int getPoolSize()
      Returns:
      the maximum number of managed threads
    • 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.

      Parameters:
      taskDecorator - value to set
    • initializeExecutor

      protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler)
      Specified by:
      initializeExecutor in class ExecutorConfigurationSupport
    • execute

      public void execute(Runnable task)
      Specified by:
      execute in interface Executor
      Specified by:
      execute in interface TaskExecutor
    • submit

      public Future<?> submit(Runnable task)
      Specified by:
      submit in interface AsyncTaskExecutor
    • submit

      public <T> Future<T> submit(Callable<T> task)
      Specified by:
      submit in interface AsyncTaskExecutor
    • shutdown

      public void shutdown()
      Overrides:
      shutdown in class ExecutorConfigurationSupport