Task Scheduling (@Scheduled) — Spring Technical Interview Questions & Answers
Running recurring background jobs.
Task Scheduling (@Scheduled)
- @Scheduled runs a method on a timer (every minute, cron, etc.).
- Enable with @EnableScheduling.
- Good for cleanup jobs, sync tasks, reminders.
- Keep jobs idempotent when possible (safe if run twice).
- Declarative scheduling without an external cron on the server.
Technical Interview Tip: Mention @EnableScheduling + one @Scheduled example idea.
Code Examples for Task Scheduling (@Scheduled)
Task Scheduling (@Scheduled) — working example
// Topic: Task Scheduling (@Scheduled)
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
class TopicController {
@GetMapping("/api/topic")
String topic() {
return "Spring Boot: Task Scheduling (@Scheduled)";
}
}Task Scheduling (@Scheduled): GET /api/topic returns this title string.
How to Explain Task Scheduling (@Scheduled) to an Interviewer
What is Task Scheduling (@Scheduled) (sb misc)?
Used for a short Task Scheduling @Scheduled sb misc example a small REST app Not just the heading
Give one small example of Task Scheduling (@Scheduled) (sb misc).
the smallest Task Scheduling @Scheduled sb misc example you can type Running recurring background jobs
What mistake do beginners make with Task Scheduling (@Scheduled) (sb misc)?
only saying “Task Scheduling @Scheduled sb misc” with no example Show the fix
Where do you use Task Scheduling (@Scheduled) (sb misc)?
a small REST app a short Task Scheduling @Scheduled sb misc example