简体   繁体   English

当 TaskScheduler 未设置/可用时,与 Spring @Scheduled/@EnableScheduling 注册器一起使用的单线程默认调度程序的行为

[英]Behavior of the single-threaded default scheduler used with Spring @Scheduled/@EnableScheduling registrar when a TaskScheduler is not setup/available

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 "EnableScheduling的 Spring 文档中所述,当 TaskScheduler 池未设置/可用/可解析时,“将在注册器中创建和使用本地单线程默认调度程序

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?现在,当这种情况发生时,这个默认调度程序的性质和行为是什么,特别是 w.r.t,它的线程是否可能由于执行期间未捕获/处理的故障而终止?

Is this default scheduler an instance of ThreadPoolTaskScheduler ?这个默认调度程序是ThreadPoolTask Scheduler 的一个实例吗? If so then what is its default ErrorHandler strategy?如果是这样,那么它的默认ErrorHandler策略是什么? 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 ".或者这个默认调度程序是一个更简单的调度程序,只是一个ScheduledExecutorService的实例,它是通过调用Executors.html#newSingleThreadScheduledExecutor()构造的,如那里所述,“如果这个单线程由于在关闭之前的执行期间发生故障而终止,一个新的如果需要执行后续任务,将取而代之。”

Thanks谢谢

Found the answers myself after looking at the Spring task scheduling source code.自己看了Spring任务调度源码后找到了答案。 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?现在,当这种情况发生时,这个默认调度程序的性质和行为是什么,特别是 w.r.t,它的线程是否可能由于执行期间未捕获/处理的故障而终止?

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.用户提交的任务被装饰为org.springframework.scheduling.support.DelegatingErrorHandlingRunnable包装用户 Runnable,捕获从它抛出的任何异常或错误,并允许org.springframework.util.ErrorHandler处理它。 Here is the source .这里是来源

For this one,对于这个,

Is this default scheduler an instance of ThreadPoolTaskScheduler?这个默认调度程序是 ThreadPoolTaskScheduler 的一个实例吗? If so then what is its default ErrorHandler strategy?如果是这样,那么它的默认 ErrorHandler 策略是什么? 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()...或者这个默认调度程序是一个更简单的调度程序,只是通过调用 Executors.html#newSingleThreadScheduledExecutor() 构造的 ScheduledExecutorService 的一个实例...

Answer is its an instance of org.springframework.scheduling.concurrentConcurrentTaskScheduler that does wrap a ScheduledExecutorService constructed from invoking Executors.html#newSingleThreadScheduledExecutor() .答案是它的一个org.springframework.scheduling.concurrentConcurrentTaskScheduler实例,它包装了一个通过调用Executors.html#newSingleThreadScheduledExecutor()构造的 ScheduledExecutorService。

The ErrorHandler strategy is to log the user Throwables at error level. ErrorHandler策略是在错误级别记录用户 Throwables。 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.此外,重复任务也将抑制用户 Throwable 并且不传播(因此不会阻止任务的后续执行),而对于一次性任务,它将按预期传播(重新抛出)。 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谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM