SimpleAsyncTaskScheduler: Returned ScheduledFuture does not track provided task execution #32589
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: documentation
A documentation task
Milestone
Affects: Spring Framework 6.1.5
The ScheduledFuture returned by SimpleAsyncTaskScheduler does not track the execution state of the submitted task, but rather tracks the execution state of the scheduling of the task. This is a noted difference from the ThreadPoolTaskScheduler where the returned ScheduledFuture tracks the execution of the submitted task itself.
This has consequences for anyone migrating their taskScheduler to use virtual threads and currently interact with the returned future, since SimpleAsyncTaskScheduler is the recommended class to do so.
From my investigation this is caused by the wrapping of the provided task into a delegate task which submits the provided task to the underlying SimpleAsyncTaskExecutor execute method. This delegation effectively hides the execution of the provided task from the ScheduledExecutorService meaning once the task is submitted to the underlying execute method it is no longer able to track the status of the task execution and sets its state to success.
Below I have included some test cases that demonstrate the effects of this in both the successful and exceptional cases. They can also be found in the following repo https://github.com/Sheikah45/TaskSchedulerExample
If it is not possible to allow the delegating task status to be tracked I would suggest adding a note to the documentation of the SimpleAsyncTaskScheduler to make it clear what the expected behavior of the returned Scheduled future is, since as it stands now the behavior appears to contradict the documentation of the schedule methods which state:
Returns: a ScheduledFuture representing pending completion of the task
The text was updated successfully, but these errors were encountered: