Spring Scheduled 注释中的固定速率和固定延迟有什么区别? [英] What's the difference between fixed rate and fixed delay in Spring Scheduled annotation?

查看:50
本文介绍了Spring Scheduled 注释中的固定速率和固定延迟有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Spring 实施计划任务,并且我看到有两种类型的时间配置选项可以从上次调用开始再次安排工作.这两种类型有什么区别?

I am implementing scheduled tasks using Spring, and I see there are two types of config options for time that schedule work again from the last call. What is the difference between these two types?

 @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
         */
    }
    

    这篇关于Spring Scheduled 注释中的固定速率和固定延迟有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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