Scheduling with @Scheduled
Run tasks on a fixed rate or cron.
Scheduling in Spring Boot
Spring Boot lets you run methods automatically on a schedule without any external cron daemon. You annotate a method with @Scheduled and Spring invokes it repeatedly in the background.
- Perfect for cleanup jobs, polling, report generation
- No extra infrastructure needed
Enabling scheduling
Scheduling is off by default. You turn it on with @EnableScheduling on a configuration class (often the main application class).
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableScheduling
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}All lessons in this course
- Scheduling with @Scheduled
- Spring Batch Jobs and Steps
- Readers, Processors, and Writers
- Restart and Error Handling