Spring Scheduled注解中固定速率和固定延迟有什么区别?

新手上路,请多包涵

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

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

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

原文由 Adam 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 712
1 个回答
  • 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
     */
}

原文由 kuhajeyan 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题