Spring handles scheduled and periodic task execution through the @Scheduled annotation, which lets a method run on a fixed interval, a delay, or a cron expression.
A nightly cleanup job that deletes expired records can be scheduled with @Scheduled(cron = "0 0 2 * * *") to run every day at 2am without any external cron setup.
@Configuration
@EnableScheduling
public class SchedulingConfig {
}
@Component
public class CleanupJob {
@Scheduled(cron = "0 0 2 * * *")
public void purgeExpiredRecords() {
// cleanup logic
}
}A concise interview answer is
I use @Scheduled methods, enabled with @EnableScheduling, to run tasks on a fixed rate, fixed delay, or cron expression without an external scheduler. Since all scheduled tasks share one thread by default, I configure a custom TaskScheduler with a thread pool, or use @Async, when tasks need to run in parallel.
Last updated: 16 July 2026
Previous question: Explain the role of the @Async annotation in Spring Framework.
Next question: Discuss the benefits and considerations of using externalized configuration in Spring Boot.