Basic steps for executing jobs using quartz scheduler
- Step 1: Create a Job Class that implements the quartz job interface
- Step 2: Create a handle to the job in a separate class, e.g. Main
- Step 3: Create a Trigger, independent of the job, specify how often you want a job to be executed
- Step 4: Create a Scheduler and associate a trigger with a job
- Step 5: Start the scheduler which will trigger the job based on the configuration present in the trigger
Sample Triggers,This trigger will run any job, once, now.
Trigger triggerNow = TriggerBuilder.newTrigger() .withIdentity("NowTrigger").startNow().build();This trigger will run any job every 1 second, indefinitely.
Trigger triggerEverySecond = TriggerBuilder.newTrigger().withIdentity("NameOneSecondTrigger", "GroupForever").withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1).repeatForever()).build();