Reputation:
how to create scheduler which triggers a job at every 13 hours in java for example if it starts at
Upvotes: 1
Views: 632
Reputation: 93
In Spring Boot, you can just annotate a method with the @Scheduled annotation and the main class with the @EnableScheduling.
Examples:
Main class in Spring application
@EnableScheduling
@SpringBootApplication
public class ScheduledDemoApplication {
public static void main(String[] args) {
SpringApplication.run(ScheduledDemoApplication.class, args);
}
}
and create a method in a separate class that will be triggered on a schedule:
@Scheduled(some cron exp here)
public void execute() {
// some logic that will be executed on a schedule
}
This should work fine.
Here is a good article on how to schedule a Spring Boot task.
Upvotes: 1