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
logger
Fields inherited from interface org.springframework.core.task.AsyncTaskExecutor
TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
int
protected ExecutorService
initializeExecutor
(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) void
setPoolSize
(int poolSize) Set the the maximum number of managed threads.void
setTaskDecorator
(TaskDecorator taskDecorator) Specify a customTaskDecorator
to be applied to anyRunnable
about to be executed.void
shutdown()
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, setWaitForTasksToCompleteOnShutdown, start, stop, stop
Methods inherited from class org.springframework.scheduling.concurrent.CustomizableThreadFactory
newThread
Methods inherited from class org.springframework.util.CustomizableThreadCreator
createThread, getDefaultThreadNamePrefix, getThreadGroup, getThreadNamePrefix, getThreadPriority, isDaemon, nextThreadName, setDaemon, setThreadGroup, setThreadGroupName, setThreadPriority
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
Methods inherited from interface org.springframework.core.task.AsyncTaskExecutor
execute, submitCompletable, submitCompletable
Methods inherited from interface org.springframework.scheduling.SchedulingTaskExecutor
prefersShortLivedTasks
Methods 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
)
-
getPoolSize
public int getPoolSize()- Returns:
- the maximum number of managed threads
-
setTaskDecorator
Specify a customTaskDecorator
to be applied to anyRunnable
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 plainRunnable
execution viaexecute
calls. In case of#submit
calls, the exposedRunnable
will be aFutureTask
which does not propagate any exceptions; you might have to cast it and callFuture#get
to evaluate exceptions. See theThreadPoolExecutor#afterExecute
javadoc for an example of how to access exceptions in such aFuture
case.- Parameters:
taskDecorator
- value to set
-
initializeExecutor
protected ExecutorService initializeExecutor(ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) - Specified by:
initializeExecutor
in classExecutorConfigurationSupport
-
execute
- Specified by:
execute
in interfaceExecutor
- Specified by:
execute
in interfaceTaskExecutor
-
submit
- Specified by:
submit
in interfaceAsyncTaskExecutor
-
submit
- Specified by:
submit
in interfaceAsyncTaskExecutor
-
shutdown
public void shutdown()- Overrides:
shutdown
in classExecutorConfigurationSupport
-