Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

Explain the difference between fixedRate, fixedDelay and cron in @Scheduled, and what happens with fixedRate when one execution takes longer than the interval.

fixedDelay waits the given time after one execution finishes before starting the next, while fixedRate starts executions at a fixed interval measured from the start of each one. cron runs at calendar times, such as 02:00 every day, in the zone given by its zone attribute. When a fixedRate execution takes longer than the interval, the next execution does not run in parallel: it starts as soon as the late one finishes.

Why this question is asked

Almost every Spring service has a few @Scheduled methods: refresh a cache, poll a table, send a daily report. The three options look similar in code, but they behave very differently when a run is slow, and that difference is behind many production surprises, from jobs that drift later every day to polling loops that suddenly run back to back. Interviewers ask this to see whether we understand the timing model rather than just the syntax. In this answer, we will recap how @Scheduled works, compare fixedDelay and fixedRate on a timeline, see exactly what happens when a fixedRate run overruns, look at cron with time zones, and finish with initialDelay and timeUnit.

1A Quick Recap of @Scheduled

@Scheduled marks a method that Spring should call on a schedule. It only works when scheduling is switched on with @EnableScheduling on a configuration class. At startup, Spring finds every annotated method and registers it with a TaskScheduler, an object that keeps a list of tasks and the time each should next run. In Spring Boot, that is by default a ThreadPoolTaskScheduler with a single thread.

The method must take no arguments, and its return value is ignored. The annotation tells the scheduler when to run it, and there are three ways to say that: fixedDelay, fixedRate and cron.

2FixedDelay and fixedRate on a Timeline

The difference is where the clock starts. With fixedDelay, the clock starts when the previous run ends. With fixedRate, it starts when the previous run starts. Here are both with a 10-second interval and a task that takes 4 seconds.

Java
@Scheduled(fixedDelay = 10_000) // 10 s after the previous run ends
void pollQueue() { work(4); }
// starts at: 0 s, 14 s, 28 s, 42 s ... (4 s of work + 10 s pause each time)
@Scheduled(fixedRate = 10_000) // every 10 s, measured from each start
void refreshPrices() { work(4); }
// starts at: 0 s, 10 s, 20 s, 30 s ... (always 10 s apart while the work fits)
Start times with a 10 second interval and 4 second runs
RunfixedDelay = 10 sfixedRate = 10 s
10 s0 s
214 s10 s
328 s20 s
442 s30 s
fixedDelay counts from the end of each run, fixedRate from the start.

So fixedDelay guarantees a pause between runs and drifts later when the work gets slower, which suits polling: we never hammer a system that is already slow. fixedRate keeps a steady rhythm, which suits work that should happen a set number of times per hour, such as sampling a metric every 10 seconds.

3When a fixedRate Run Takes Longer Than the Interval

Now suppose one run of refreshPrices takes 25 seconds instead of 4. Executions of the same task never overlap on the default scheduler: it will not start a second copy of the method while the first is still running. Instead, the runs that were due at 10 s and 20 s are late. When the long run finishes at 25 s, the next run starts immediately.

There is a subtle detail. The default scheduler is built on Java's ScheduledThreadPoolExecutor, which computes each next time as 'the planned time of this run plus the period', not 'now plus the period'. So after an overrun, the task runs back to back until it has caught up with its original rhythm.

Java
@Scheduled(fixedRate = 10_000)
void refreshPrices() { ... } // run 1 takes 25 s, later runs take 4 s
// run 1: planned 0 s, starts 0 s, ends 25 s (overran)
// run 2: planned 10 s, starts 25 s, ends 29 s (late, starts right away)
// run 3: planned 20 s, starts 29 s, ends 33 s (still late, back to back)
// run 4: planned 30 s, starts 33 s, ends 37 s
// run 5: planned 40 s, starts 40 s (caught up)

Two things can change this picture. If we also mark the method @Async, the scheduler only hands it to another executor and returns at once, so runs do overlap. And if virtual threads are enabled, Spring Boot uses a SimpleAsyncTaskScheduler that starts each run on a new virtual thread, where fixed-rate runs may overlap too; check your version before relying on either behaviour. If overlapping would be harmful, fixedDelay is the safer choice.

4Cron: Running at Calendar Times

fixedDelay and fixedRate are about intervals. cron is about the calendar: 'at 02:00 every day' or 'every weekday at 06:30'. Spring's cron expressions have six fields: second, minute, hour, day of month, month and day of week.

Java
@Scheduled(cron = "0 0 2 * * *", zone = "Europe/Berlin") // 02:00 Berlin time, every day
void nightlyReport() { ... }
@Scheduled(cron = "0 30 6 * * MON-FRI") // 06:30 on weekdays, server time zone
void morningDigest() { ... }

Without the zone attribute, the expression is evaluated in the JVM's default time zone, which depends on how the server or container was set up. Setting zone explicitly makes the schedule independent of the machine, which matters as soon as the service moves to a cloud region or a container with UTC as its default. A cron task that overruns behaves like fixedRate on the default scheduler: the next run waits for the current one, but a run that is missed while the previous one is still going is simply the next matching time after it finishes, with no catching up.

5InitialDelay, timeUnit and Values From Configuration

initialDelay postpones the first execution of a fixedDelay or fixedRate task, which is useful to let caches warm up or other services start after a deployment. timeUnit, available since Spring Framework 5.3, says what unit the numbers are in, so we do not have to write milliseconds everywhere. Each attribute also has a String form that accepts property placeholders and durations, so the schedule can come from configuration.

Java
@Scheduled(fixedRate = 30, initialDelay = 5, timeUnit = TimeUnit.SECONDS)
void heartbeat() { ... } // first run 5 s after startup, then every 30 s
@Scheduled(fixedDelayString = "${sync.delay:PT1M}") // one minute unless configured
void sync() { ... }

Taking schedules from configuration lets operations change a polling interval without a new build, and it is also how we disable a cron task in one environment, by setting its value to "-".

6Follow-up questions

Which should I use for polling a database table?

Usually fixedDelay. It guarantees a pause after each poll, so when the database is slow the polling slows down with it instead of running back to back. fixedRate is better when the rhythm itself matters, such as recording a sample every 10 seconds.

Can two different @Scheduled methods run at the same time?

Only if the scheduler has more than one thread. Spring Boot's default scheduler has a pool size of 1, so all scheduled methods share one thread and wait for each other. Setting spring.task.scheduling.pool.size lets different tasks run in parallel, while each single task still does not overlap itself.

Does a cron schedule catch up on runs missed while the application was down?

No. Spring's scheduler keeps its state in memory, so after a restart it simply computes the next matching time from now. If missed runs must be made up, we need a persistent scheduler such as Quartz with misfire handling, or a job that works out what it missed from its own records.

7Conclusion

In this answer, we saw that fixedDelay counts its interval from the end of each run, fixedRate counts from the start, and cron follows calendar times in the zone we give it. When a fixedRate run overruns, the default scheduler never overlaps it with itself; the late runs start as soon as it finishes and run back to back until the original rhythm is restored, unless @Async or a virtual-thread scheduler changes the picture. We also used initialDelay, timeUnit and configuration-driven schedules.

What to say in the interviewAbout 80 seconds aloud

Open with

fixedDelay measures the interval from the end of the previous run, so with a 10-second delay and 4-second work it starts at 0, 14, 28 seconds; there is always a pause, which is what I want for polling. fixedRate measures from the start of each run, so the same task starts at 0, 10, 20; that keeps a steady rhythm. cron is calendar-based, six fields in Spring starting with seconds, like 0 0 2 star star star for 2 a.m., and I always set the zone attribute so it does not depend on the server's default time zone.

Then, if they want more

If a fixedRate run takes longer than the interval, the default scheduler does not start a second copy in parallel; the next run starts as soon as the long one finishes, and because the next time is computed from the planned time, it runs back to back until it catches up.

That changes if the method is also @Async or if virtual threads are on, where runs can overlap, so I would check the version and prefer fixedDelay when overlap is harmful. initialDelay delays the first run, timeUnit lets me write values in seconds or minutes, and the String variants let me take schedules from configuration.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 5
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Batch reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain the difference between fixedRate, fixedDelay and cron in @Scheduled, and what...": https://scrivio-interview-library.netlify.app/spring-boot/scheduling/db46ec6349/