Instantiating the Scheduler
Before you can use the Scheduler, it needs to be instantiated. To do this, you use a SchedulerFactory.
Some users of Quartz keep an instance of a factory in a JNDI store, others find it just as easy (or easier) to instantiate and use a factory instance directly (as in the example below).
Once a scheduler is instantiated, it can be started, placed in stand-by mode, and shutdown. Be aware that once you shut a scheduler down, you cannot restart it without reinstantiating it. Triggers will not fire (and therefore, jobs will not execute) until the scheduler has been started. Nor will they fire while the scheduler is in the paused state.
The following code snippet instantiates and starts a scheduler, and schedules a job for execution.
SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();
sched.start();
// define the job and tie it to our HelloJob class
JobDetail job = newJob(HelloJob.class)
.withIdentity("myJob", "group1")
.build();
// Trigger the job to run now, and then every 40 seconds
Trigger trigger = newTrigger()
.withIdentity("myTrigger", "group1")
.startNow()
.withSchedule(simpleSchedule()
.withIntervalInSeconds(40)
.repeatForever())
.build();
// Tell quartz to schedule the job using our trigger
sched.scheduleJob(job, trigger);