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
ConstructorDescriptionCreate a newVirtualThreadTaskExecutor
without thread naming.VirtualThreadTaskExecutor
(String threadNamePrefix) Create a newVirtualThreadTaskExecutor
with thread names based on the given thread name prefix followed by a counter (e.g. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Execute the giventask
.final ThreadFactory
Return the underlying virtualThreadFactory
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.core.task.AsyncTaskExecutor
execute, submit, submit, submitCompletable, submitCompletable
-
Constructor Details
-
VirtualThreadTaskExecutor
public VirtualThreadTaskExecutor()Create a newVirtualThreadTaskExecutor
without thread naming. -
VirtualThreadTaskExecutor
Create a newVirtualThreadTaskExecutor
with thread names based on the given thread name prefix followed by a counter (e.g. "test-0").- Parameters:
threadNamePrefix
- the prefix for thread names (e.g. "test-")
-
-
Method Details
-
getVirtualThreadFactory
Return the underlying virtualThreadFactory
. Can also be used for custom thread creation elsewhere. -
execute
Description copied from interface:TaskExecutor
Execute 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:
execute
in interfaceExecutor
- Specified by:
execute
in interfaceTaskExecutor
- Parameters:
task
- theRunnable
to execute (nevernull
)
-