BackendBench
Coffee
Spot the Bug #45

Sixty runs at nine o'clock

A medium Java puzzle in the scheduling and cron mistakes family. One line below contains a real bug. Try to spot it first, then read why it fails and how to fix it.

mediumScheduling and cron mistakesbuggy line: 7

Highlighted: line 7. Play this one as a puzzle without the answer.

What is wrong

The first field is seconds, and * means every second. The job runs 60 times between 09:00:00 and 09:00:59, so every subscriber receives the digest sixty times.

The fix

@Scheduled(cron = "0 0 9 * * *")

How to avoid it next time

Put 0 in the seconds field unless you really want sub-minute scheduling.

Want the background? Read @Scheduled jobs in the Java concepts library.

About scheduling and cron mistakes

Cron dialects differ in field count and meaning. Spring has six fields starting with seconds, Unix has five, Quartz needs a question mark in one day field, and time zones decide when midnight actually is.

In code review: Count the fields and check which dialect the framework expects. Confirm the time zone and what the day-of-week field numbers mean in that dialect.

More puzzles in this family

๐Ÿž Play today's puzzleAll 132 bugsโ† #44#46 โ†’

Frequently asked questions

What is the bug in "Sixty runs at nine o'clock"?

The first field is seconds, and * means every second. The job runs 60 times between 09:00:00 and 09:00:59, so every subscriber receives the digest sixty times. The faulty line is line 7: @Scheduled(cron = "* 0 9 * * *")

How do I fix it?

Replace it with: @Scheduled(cron = "0 0 9 * * *"). Put 0 in the seconds field unless you really want sub-minute scheduling.

How do I catch scheduling and cron mistakes in code review?

Count the fields and check which dialect the framework expects. Confirm the time zone and what the day-of-week field numbers mean in that dialect.

Is there a new puzzle every day?

Yes. The daily Spot the Bug puzzle picks one of these snippets for each UTC day, with the difficulty set by the weekday. Your streak is stored only in your browser.

More tools you might need