Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

A job scheduled with @Scheduled(cron = "0 30 2 * * *") ran twice on one night and not at all on another night in spring. The servers use the Europe/Berlin time zone. Explain and fix.

In Europe/Berlin, 02:30 is inside the daylight saving transition hour: on the last Sunday of March clocks jump from 02:00 to 03:00, so 02:30 does not exist and the job can be skipped, and on the last Sunday of October clocks go back from 03:00 to 02:00, so 02:30 happens twice and the job can run twice. Exactly how Spring's cron handling treats these nights depends on the version, so the fix should not rely on it: schedule business jobs outside the 02:00 to 03:00 window or set zone = "UTC", make the job idempotent per business date, and document which time zone defines the business date.

Why this question is asked

Time zone bugs are memorable because they only happen twice a year, usually at night, and they look impossible in the logs: the job ran twice, a day apart, at the same time. Interviewers ask this question because it tests whether we know how local time behaves around daylight saving changes and whether we fix the design rather than the symptom. In this answer, we will recap what happens to local time in Berlin on the two transition nights, see how a cron scheduler can skip or double a run, check the facts with java.time, and go through the fixes: moving the time, using UTC, idempotency per business date and a written time zone rule.

1A Quick Recap of the Two Transition Nights

Europe/Berlin is at UTC+1 in winter (CET) and UTC+2 in summer (CEST). The switch happens at 01:00 UTC on the last Sunday of March and the last Sunday of October. In local time, that means two odd nights.

In spring, on 29 March 2026, clocks jump from 02:00 straight to 03:00. Local times from 02:00 to 02:59 never happen; there is a gap. In autumn, on 25 October 2026, clocks go from 03:00 back to 02:00. Local times from 02:00 to 02:59 happen twice, once at UTC+2 and an hour later at UTC+1; there is an overlap. A job at 02:30 local time sits right in the middle of both.

Java
ZoneId berlin = ZoneId.of("Europe/Berlin");
ZoneRules rules = berlin.getRules();
rules.getValidOffsets(LocalDateTime.of(2026, 3, 29, 2, 30)); // []: 02:30 does not exist
ZonedDateTime.of(LocalDateTime.of(2026, 3, 29, 2, 30), berlin); // 2026-03-29T03:30+02:00 (moved forward)
rules.getValidOffsets(LocalDateTime.of(2026, 10, 25, 2, 30)); // [+02:00, +01:00]: it happens twice
ZonedDateTime first = ZonedDateTime.of(LocalDateTime.of(2026, 10, 25, 2, 30), berlin);
first.toInstant(); // 2026-10-25T00:30:00Z
first.withLaterOffsetAtOverlap().toInstant(); // 2026-10-25T01:30:00Z, one hour later
02:30 local time in Berlin around the transitions
NightWhat the clock does02:30 localRisk
Normal nightnothingoncenone
29 March 202602:00 jumps to 03:00never existsrun skipped or moved
25 October 202603:00 goes back to 02:00occurs at 00:30Z and 01:30Zrun twice

Notice that java.time does not throw for a time in the gap; it quietly moves it forward by the length of the gap, and for a time in the overlap it picks the earlier offset unless we ask for the later one. Any scheduler built on these rules has to make the same choices, and different choices give different behaviour.

2How a Cron Scheduler Skips or Doubles a Run

A cron scheduler repeatedly asks 'what is the next time after now that matches the expression?'. For 0 30 2 * * *, it looks for the next moment whose local time reads 02:30:00.

On the spring night, no such moment exists on 29 March. Depending on the implementation, the scheduler either moves to the next day, so that night has no run, or runs at the adjusted time, 03:30. On the autumn night, the first 02:30 comes at 00:30 UTC. After that run, the scheduler asks for the next matching time after it, and an hour later the local clock reads 02:30 again, at 01:30 UTC. A scheduler that looks only at local time finds a match and runs the job a second time.

Spring's CronExpression, introduced in 5.3, works with ZonedDateTime and has had fixes in this area across versions, so the exact behaviour for a time inside the gap or the overlap should be checked for your version. What matters for the design is that any scheduled time inside the transition hour is ambiguous, and our job must not depend on how the scheduler resolves it.

3Fix 1: Move the Job Out of the Transition Window, or Use UTC

The simplest fix is to choose a time that exists exactly once every night. In Europe the transition affects local times from 02:00 to 02:59, so scheduling at 01:30 or 03:30 avoids it. Many teams adopt a simple rule: no business jobs between 01:00 and 04:00 local time, which also covers other European zones.

Java
// Option A: a local time outside the transition window
@Scheduled(cron = "0 30 3 * * *", zone = "Europe/Berlin")
public void nightlySettlement() { ... }
// Option B: UTC, which has no daylight saving
@Scheduled(cron = "0 30 1 * * *", zone = "UTC")
public void nightlySettlement() { ... }
// 01:30 UTC is 02:30 Berlin in winter and 03:30 Berlin in summer

UTC has no gaps or overlaps, so a UTC schedule fires exactly once a day, always. The trade-off is that the local time moves by an hour twice a year, which matters if the job must run after a local event, such as a branch closing at 02:00. Whichever we choose, the zone attribute should always be explicit, so the behaviour does not change when the service moves to a container whose default zone is UTC.

4Fix 2: Make the Job Idempotent per Business Date

Moving the time removes the cause we know about, but schedules also run twice for other reasons: a manual rerun, a restart, a second instance. The robust fix is that the job works on a business date, and doing that date twice changes nothing.

Java
public void nightlySettlement() {
LocalDate businessDate = LocalDate.now(clock.withZone(ZoneId.of("Europe/Berlin"))).minusDays(1);
int claimed = jdbc.update("""
INSERT INTO settlement_run (business_date, started_at) VALUES (?, now())
ON CONFLICT (business_date) DO NOTHING""", businessDate);
if (claimed == 0) {
log.info("settlement for {} already done, skipping", businessDate); // second 02:30 in October
return;
}
settlementService.settle(businessDate);
}

Notice that the job derives the business date from a clock in a defined zone, not from the run time alone, and claims it with a unique key. On the autumn night, the second run finds the date already claimed and does nothing. And if the spring night's run was skipped, a monitor that checks 'is there a settlement_run row for yesterday by 06:00?' catches it instead of finance.

5Fix 3: Document the Time Zone of the Business Date

The deeper source of this bug is that nobody decided which time zone defines 'a day' for this job. Is the settlement for a Berlin calendar day, a UTC day, or the day of the customer's own zone? The answer belongs in the job's documentation and in its code, as an explicit ZoneId, not in the server's configuration. Once it is written down, scheduling decisions follow from it: the trigger can be in any zone, as long as the job computes its business date in the agreed one.

This also prevents a quieter bug, where a job running late in the evening UTC processes the 'wrong' day for Berlin, because at 23:30 UTC it is already 00:30 or 01:30 on the next calendar day in Berlin.

6Follow-up questions

Would a Quartz CronTrigger behave differently?

Quartz has its own rules for the gap and the overlap, and they are documented as possibly surprising: a fire time in the skipped hour may not fire, and one in the repeated hour may fire once or twice depending on the version and trigger. The same fixes apply: avoid the window, or use UTC, and make the job idempotent.

Why not just run everything in UTC?

For many technical jobs that is the best choice. For business jobs tied to a local event, such as end of the trading day in Frankfurt, UTC would move the job by an hour twice a year relative to the event. Those jobs should run at a safe local time with an explicit zone, and compute their business date in that zone.

How would you test this?

Use CronExpression.parse(...).next(...) with ZonedDateTime values on the transition dates to see what your Spring version does, and unit-test the job with a fixed Clock set to both 02:30 occurrences on 25 October to check that the second run does nothing.

7Conclusion

In this answer, we saw that 02:30 in Europe/Berlin falls inside the daylight saving transition hour: it does not exist on the last Sunday of March and occurs twice on the last Sunday of October, so a cron job at that time can be skipped or run twice, with exact behaviour depending on the scheduler version. We fixed it by scheduling outside the 02:00 to 03:00 window or in UTC with an explicit zone, by making the job idempotent per business date with a unique claim, and by documenting which time zone defines the business date.

What to say in the interviewAbout 80 seconds aloud

Open with

02:30 in Europe/Berlin is inside the daylight saving transition hour. On the last Sunday of March, clocks jump from 2 to 3, so 02:30 doesn't exist, and the scheduler either skips that night or moves the run.

Then, if they want more

On the last Sunday of October, clocks go back from 3 to 2, so 02:30 happens twice, at 00:30 UTC and again at 01:30 UTC, and a scheduler that looks for the next time the local clock reads 02:30 finds it twice.

How Spring's CronExpression resolves the gap and the overlap has varied between versions, so I'd check ours, but I wouldn't rely on it either way. The fixes: first, move business jobs out of the window, for example to 03:30 with zone Europe/Berlin, or schedule in UTC, which has no transitions, accepting that the local time moves by an hour.

Always set zone explicitly. Second, make the job idempotent per business date: compute the date in a defined zone and claim it with an insert into a run table with a unique key, so the second run does nothing, and alert if yesterday's row is missing in the morning.

Third, document which time zone defines the business date, because that's the real decision behind this bug.

About this answer

Last updated
12 November 2026
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 "A job scheduled with @Scheduled(cron = "0 30 2 * * *") ran twice on one night and not at...": https://scrivio-interview-library.netlify.app/spring-boot/scheduling/d6d43a7c28/