Issue
As noted in the Spring docs for EnableScheduling, when a TaskScheduler pool is not setup/available/resolvable, "a local single-threaded default scheduler will be created and used within the registrar"
Now when this happens what is the nature & behavior of this default scheduler particularly w.r.t whether or not its thread would potentially get terminated due to a failure during execution that is not caught/handled?
Is this default scheduler an instance of ThreadPoolTaskScheduler? If so then what is its default ErrorHandler strategy ? Is it that the throwable is simply logged?
Or is this default scheduler a simpler one, simply an instance of ScheduledExecutorService that is constructed from invoking Executors.html#newSingleThreadScheduledExecutor() where in as stated there, "if this single thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks".
Thanks
Solution
Found the answers myself after looking at the Spring task scheduling source code. Sharing here for others.
For this one,
Now when this happens what is the nature & behavior of this default scheduler particularly w.r.t whether or not its thread would potentially get terminated due to a failure during execution that is not caught/handled?
Answer is as expected, it won't. User submitted tasks are decorated as a org.springframework.scheduling.support.DelegatingErrorHandlingRunnable
that wraps the user Runnable, catches any exception or error thrown from it and allows an org.springframework.util.ErrorHandler
to handle it. Here is the source.
For this one,
Is this default scheduler an instance of ThreadPoolTaskScheduler? If so then what is its default ErrorHandler strategy ? Is it that the throwable is simply logged?
Or is this default scheduler a simpler one, simply an instance of ScheduledExecutorService that is constructed from invoking Executors.html#newSingleThreadScheduledExecutor()...
Answer is its an instance of org.springframework.scheduling.concurrentConcurrentTaskScheduler
that does wrap a ScheduledExecutorService constructed from invoking Executors.html#newSingleThreadScheduledExecutor().
The ErrorHandler strategy is to log the user Throwables at error level. In addition, repeated tasks will also have the user Throwable suppressed & not propagated (so that subsequent executions of the task will not be prevented) while for one shot tasks it will be propagated (re-thrown) as expected. Here is the source.
Both of the above is what i was expecting, but wanted to make sure since the nature & behavior of this default is not clearly documented. Perhaps a little more documentation might help.
Thanks
Answered By - lmk
Answer Checked By - Mary Flores (JavaFixing Volunteer)