Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Spring Boot FAQ: Top Questions

12. How do you enable scheduling in a Spring Boot application?

Spring Boot allows scheduling of tasks using the @Scheduled annotation. You must enable it using @EnableScheduling.

πŸ—ΊοΈ Steps:

  1. Add @EnableScheduling in your main configuration class.
  2. Annotate a method with @Scheduled.

πŸ“₯ Example:

@Scheduled(fixedRate = 5000)
public void reportCurrentTime() {
  System.out.println("Task runs every 5 seconds");
}

πŸ† Expected Output:

Console prints message every 5 seconds.

πŸ› οΈ Use Cases:

  • Periodic data polling.
  • Running maintenance tasks.