0Pricing
Spring Boot 4 Microservices & REST APIs · Lesson

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

  1. Scheduling with @Scheduled
  2. Spring Batch Jobs and Steps
  3. Readers, Processors, and Writers
  4. Restart and Error Handling
← Back to Spring Boot 4 Microservices & REST APIs