How to reschedule a Quartz Job ?
Supposing that you have scheduled a Job with a GUI interface and you want to allow the user to change the scheduling plan of this job. Here we are first defining a Job which is triggered to start every 30 seconds. After a pause, the Job is rescheduled to start every 10 seconds:
JobDetail job = new JobDetail("job1", "group1", TestJob.class); Trigger trigger = TriggerUtils.makeSecondlyTrigger(30); trigger.setName("trigger1"); trigger.setGroup("group1"); trigger.setJobName("job1"); trigger.setJobGroup("group1"); Date ft = scheduler.scheduleJob(job, trigger); System.out.println("Job will run at "+ft Thread.sleep(10000); trigger = TriggerUtils.makeSecondlyTrigger(10); trigger.setName("trigger1"); trigger.setGroup("group1"); trigger.setJobName("job1"); trigger.setJobGroup("group1"); ft = scheduler.rescheduleJob("trigger1", "group1", trigger); System.out.println("Job rescheduled to run at: " + ft); out.println("Job rescheduled");
Where Quartz stores Jobs ?
I guess you noticed the property:
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
What does it mean ? the Quartz framework provides two basic types of JobStores. The first type, which utilizes ordinary memory (RAM) to persist Scheduler information, is called RAMJobStore. This type of JobStore is the easiest to configure and get up and running. For many applications, this JobStore will be sufficient. However, since the Scheduler information is stored in the memory assigned to the JVM, when the application is stopped, all knowledge of the schedule is lost. If you need to persist schedule information between restarts, then you're going to need the second type of JobStore.
The second type of JobStore actually comes with two different implementations in the framework, but both are commonly referred to as JDBC JobStores. Both JDBC JobStores use a JDBC driver and require a backing from a relational database to persist the scheduler information. The two types differ in whether or not you want to control the database transactions or relinquish control to an application container such as JBoss. (This is similar to the difference between Bean Managed Transactions or Container Managed Transactions from the J2EE world.
In order to work with JDBC Stores, the first thing to do is to create the required tables on the DB (you can find the scripts under doc/DbTables ), then choose the appropriate Jdbc Store in quartz-service.xml
This is an example for JobStoreCMT:
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreCMT
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource = QUARTZ
org.quartz.jobStore.nonManagedTXDataSource = QUARTZ_NO_TX
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.dataSource.QUARTZ.jndiURL = java:/jdbc/QuartzDS
org.quartz.dataSource.QUARTZ_NO_TX.jndiURL = java:/jdbc/QuartzNoTxDS
- << Prev