01.Job Scheduler - Project creation
Job Scheduler - Project Creation
This is implementing using two ways.
1.Using @Scheduler annotation.
2.Using Quartz scheduler (In the previous example, we executed scheduled tasks, but at the same time, we could not dynamically set the start time of the job, or pass parameters to it. To solve these problems, you can directly use Quartz.)
Quartz dependency is not necessary to implement Scheduler. This has been added for future Quartz project implementation.
Using @Scheduler
Need to add @EnableScheduling to main class.
@SpringBootApplication
@EnableScheduling
public class JobScheduleApplication {
public static void main(String[] args) {
SpringApplication.run(JobScheduleApplication.class, args);
}
}
This is a simple scheduler class.
@Component
public class SchedulerTest {
@Scheduled(cron = "0/5 * * * * ?")
public void everyFiveSeconds() {
System.out.println("Scheduler Executed.EveryFiveSeconds Scheduler: " + new Date());
}
}
,,,
Comments
Post a Comment