code4food code4food - 3 years ago 202
Java Question

what different between fixed rate and fixed delay in schedule spring?

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
}

Answer Source
  • fixedRate : makes Spring run the task on periodic intervals even if the last invocation may be still running.
  • fixedDelay : specifically controls the next execution time when the last execution finishes.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download