Class VirtualThreadPoolTaskExecutor
- All Implemented Interfaces:
Serializable,Executor,ThreadFactory,EventListener,Aware,BeanNameAware,DisposableBean,InitializingBean,ApplicationContextAware,ApplicationListener<ContextClosedEvent>,Lifecycle,Phased,SmartLifecycle,AsyncTaskExecutor,TaskExecutor,SchedulingTaskExecutor
- See Also:
-
Field Summary
Fields inherited from class org.springframework.scheduling.concurrent.ExecutorConfigurationSupport
DEFAULT_PHASE, loggerFields inherited from interface org.springframework.core.task.AsyncTaskExecutor
TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected ExecutorServiceinitializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) voidsetPoolSize(int poolSize) Set the the maximum number of managed threads.voidsetTaskDecorator(TaskDecorator taskDecorator) Specify a customTaskDecoratorto be applied to anyRunnableabout to be executed.voidsetTaskTerminationTimeout(long taskTerminationTimeout) Specify a timeout (in milliseconds) for task termination when closing this executor.voidshutdown()Future<?> <T> Future<T> Methods inherited from class org.springframework.scheduling.concurrent.ExecutorConfigurationSupport
afterExecute, afterPropertiesSet, beforeExecute, cancelRemainingTask, destroy, getPhase, initialize, initiateEarlyShutdown, initiateShutdown, isRunning, onApplicationEvent, setAcceptTasksAfterContextClose, setApplicationContext, setAwaitTerminationMillis, setAwaitTerminationSeconds, setBeanName, setPhase, setRejectedExecutionHandler, setThreadFactory, setThreadNamePrefix, setVirtualThreads, setWaitForTasksToCompleteOnShutdown, start, stop, stopMethods inherited from class org.springframework.scheduling.concurrent.CustomizableThreadFactory
newThreadMethods inherited from class org.springframework.util.CustomizableThreadCreator
createThread, getDefaultThreadNamePrefix, getThreadGroup, getThreadNamePrefix, getThreadPriority, isDaemon, nextThreadName, setDaemon, setThreadGroup, setThreadGroupName, setThreadPriorityMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecutionMethods inherited from interface org.springframework.core.task.AsyncTaskExecutor
execute, submitCompletable, submitCompletableMethods inherited from interface org.springframework.scheduling.SchedulingTaskExecutor
prefersShortLivedTasksMethods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup
-
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 isInteger.MAX_VALUE)
-
setTaskTerminationTimeout
public void setTaskTerminationTimeout(long taskTerminationTimeout) Specify a timeout (in milliseconds) for task termination when closing this executor. The default is 0, not waiting for task termination at all.Note that a concrete >0 timeout specified here will lead to the wrapping of every submitted task into a task-tracking runnable which involves considerable overhead in case of a high number of tasks. However, for a modest level of submissions with longer-running tasks, this is feasible in order to arrive at a graceful shutdown.
- Parameters:
taskTerminationTimeout- the timeout in milliseconds- See Also:
-
setTaskDecorator
Specify a customTaskDecoratorto be applied to anyRunnableabout to be executed.Note that such a decorator is not necessarily being applied to the user-supplied
Runnable/Callablebut 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
TaskDecoratorimplementations is limited to plainRunnableexecution viaexecutecalls. In case of#submitcalls, the exposedRunnablewill be aFutureTaskwhich does not propagate any exceptions; you might have to cast it and callFuture#getto evaluate exceptions. See theThreadPoolExecutor#afterExecutejavadoc for an example of how to access exceptions in such aFuturecase.- Parameters:
taskDecorator- value to set
-
initializeExecutor
protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) - Specified by:
initializeExecutorin classExecutorConfigurationSupport
-
execute
- Specified by:
executein interfaceExecutor- Specified by:
executein interfaceTaskExecutor
-
submit
- Specified by:
submitin interfaceAsyncTaskExecutor
-
submit
- Specified by:
submitin interfaceAsyncTaskExecutor
-
shutdown
public void shutdown()- Overrides:
shutdownin classExecutorConfigurationSupport
-