Quartz is a richly featured, open source job scheduling library that can be integrated within virtually any Java application - from the smallest stand-alone application to the largest e-commerce system. Quartz can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components that may execute virtually anything you may program them to do. The Quartz Scheduler includes many enterprise-class features, such as support for JTA transactions and clustering.
// Define the job and tie it to MyJob class JobDetailjob= JobBuilder.newJob(MyJob.class) .withIdentity("myJob", "group1") .build();
// Trigger the job to run now, and then every 5 seconds Triggertrigger= TriggerBuilder.newTrigger() .withIdentity("myTrigger", "group1") .startNow() .withSchedule(SimpleScheduleBuilder.simpleSchedule() .withIntervalInSeconds(5) .repeatForever()) .build();
// Schedule the job scheduler.scheduleJob(job, trigger);