Class SyncTaskExecutor
java.lang.Object
org.springframework.util.ConcurrencyThrottleSupport
org.springframework.core.task.SyncTaskExecutor
- All Implemented Interfaces:
Serializable, Executor, TaskExecutor
public class SyncTaskExecutor
extends ConcurrencyThrottleSupport
implements TaskExecutor, Serializable
TaskExecutor implementation that executes each task synchronously
in the calling thread. This can be used for testing purposes but also for
bounded execution in a Virtual Threads setup, relying on concurrency throttling
as inherited from the base class: see ConcurrencyThrottleSupport.setConcurrencyLimit(int) (as of 7.0).
Execution in the calling thread does have the advantage of participating
in its thread context, for example the thread context class loader or the
thread's current transaction association. That said, in many cases,
asynchronous execution will be preferable: choose an asynchronous
TaskExecutor instead for such scenarios.
- Since:
- 2.0
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from class ConcurrencyThrottleSupport
logger, NO_CONCURRENCY, UNBOUNDED_CONCURRENCY -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class ConcurrencyThrottleSupport
afterAccess, beforeAccess, getConcurrencyLimit, isThrottleActive, onLimitReached, setConcurrencyLimit
-
Constructor Details
-
SyncTaskExecutor
public SyncTaskExecutor()
-
-
Method Details
-
execute
Execute the giventasksynchronously, through direct invocation of itsrun()method.- Specified by:
executein interfaceExecutor- Specified by:
executein interfaceTaskExecutor- Parameters:
task- theRunnableto execute (nevernull)- Throws:
RuntimeException- if propagated from the givenRunnable
-
execute
Execute the giventasksynchronously, through direct invocation of itscall()method.- Type Parameters:
V- the returned value type, if anyE- the exception propagated, if any- Throws:
E- if propagated from the givenTaskCallback- Since:
- 7.0
-