Package org.springframework.core.task
Class VirtualThreadTaskExecutor
java.lang.Object
org.springframework.core.task.VirtualThreadTaskExecutor
- All Implemented Interfaces:
Executor,AsyncTaskExecutor,TaskExecutor
A
TaskExecutor implementation based on virtual threads in JDK 21+.
The only configuration option is a thread name prefix.
For additional features such as concurrency limiting or task decoration,
consider using SimpleAsyncTaskExecutor.setVirtualThreads(boolean) instead.
- Since:
- 6.1
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.core.task.AsyncTaskExecutor
TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE -
Constructor Summary
ConstructorsConstructorDescriptionCreate a newVirtualThreadTaskExecutorwithout thread naming.VirtualThreadTaskExecutor(String threadNamePrefix) Create a newVirtualThreadTaskExecutorwith thread names based on the given thread name prefix followed by a counter (for example, "test-0"). -
Method Summary
Modifier and TypeMethodDescriptionvoidExecute the giventask.final ThreadFactoryReturn the underlying virtualThreadFactory.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.core.task.AsyncTaskExecutor
execute, submit, submit, submitCompletable, submitCompletable
-
Constructor Details
-
VirtualThreadTaskExecutor
public VirtualThreadTaskExecutor()Create a newVirtualThreadTaskExecutorwithout thread naming. -
VirtualThreadTaskExecutor
Create a newVirtualThreadTaskExecutorwith thread names based on the given thread name prefix followed by a counter (for example, "test-0").- Parameters:
threadNamePrefix- the prefix for thread names (for example, "test-")
-
-
Method Details
-
getVirtualThreadFactory
Return the underlying virtualThreadFactory. Can also be used for custom thread creation elsewhere. -
execute
Description copied from interface:TaskExecutorExecute the giventask.The call might return immediately if the implementation uses an asynchronous execution strategy, or might block in the case of synchronous execution.
- Specified by:
executein interfaceExecutor- Specified by:
executein interfaceTaskExecutor- Parameters:
task- theRunnableto execute (nevernull)
-