进度弹簧的固定速率和固定延迟有什么不同? [英] what different between fixed rate and fixed delay in schedule spring?

查看:135
本文介绍了进度弹簧的固定速率和固定延迟有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用spring实现预定任务,我看到有2个类型的配置时间,从最近再次安排。 2配置此配置有什么不同。

I am implementing scheduled tasks using spring and i see have 2 type config time that scheduled works again from latest. What different between 2 type this config.

 @Scheduled(fixedDelay = 5000)
    public void doJobDelay() {
        // do anything
    }
  @Scheduled(fixedRate = 5000)
    public void doJobRate() {
        // do anything
    }


推荐答案


  • fixedRate:让Spring运行任务即使
    最后一次调用可能仍在运行,也会有周期性的间隔。

  • fixedDelay:专门控制
    上次执行完成时的下一个执行时间。

  • 代码:

    @Scheduled(fixedDelay=5000)
    public void updateEmployeeInventory(){
        System.out.println("employee inventory will be updated once only the last updated finished ");
        /**
         * add your scheduled job logic here
         */
    }
    
    
    @Scheduled(fixedRate=5000)
    public void updateEmployeeInventory(){
        System.out.println("employee inventory will be updated every 5 seconds from prior updated has stared, regardless it is finished or not");
        /**
         * add your scheduled job logic here
         */
    }
    

    这篇关于进度弹簧的固定速率和固定延迟有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆