Customizing Quartz properties


As it is, quartz will run against a RAMJobstore which stores in memory the Jobs. One advanced feature of this scheduler is that you can store your Jobs on a persistent store by means of a JDBC Connection or through a Datasource which is running on our application server.

In this example we will use MySQL to store our jobs, so connect to your MySQL database and create the Quartz tables (The scripts are bundled into Quartz distribution in the path docs\dbTables ):
CREATE TABLE QRTZ_JOB_DETAILS
  (
    SCHED_NAME VARCHAR(120) NOT NULL,
    JOB_NAME  VARCHAR(200) NOT NULL,
    JOB_GROUP VARCHAR(200) NOT NULL,
    DESCRIPTION VARCHAR(250) NULL,
    JOB_CLASS_NAME   VARCHAR(250) NOT NULL,
    IS_DURABLE VARCHAR(1) NOT NULL,
    IS_NONCONCURRENT VARCHAR(1) NOT NULL,
    IS_UPDATE_DATA VARCHAR(1) NOT NULL,
    REQUESTS_RECOVERY VARCHAR(1) NOT NULL,
    JOB_DATA BLOB NULL,
    PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
);
CREATE TABLE QRTZ_TRIGGERS
  (
    SCHED_NAME VARCHAR(120) NOT NULL,
    TRIGGER_NAME VARCHAR(200) NOT NULL,
    TRIGGER_GROUP VARCHAR(200) NOT NULL,
    JOB_NAME  VARCHAR(200) NOT NULL,
    JOB_GROUP VARCHAR(200) NOT NULL,
    DESCRIPTION VARCHAR(250) NULL,
    NEXT_FIRE_TIME BIGINT(13) NULL,
    PREV_FIRE_TIME BIGINT(13) NULL,
    PRIORITY INTEGER NULL,
    TRIGGER_STATE VARCHAR(16) NOT NULL,
    TRIGGER_TYPE VARCHAR(8) NOT NULL,
    START_TIME BIGINT(13) NOT NULL,
    END_TIME BIGINT(13) NULL,
    CALENDAR_NAME VARCHAR(200) NULL,
    MISFIRE_INSTR SMALLINT(2) NULL,
    JOB_DATA BLOB NULL,
    PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
    FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
        REFERENCES QRTZ_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP)
);
CREATE TABLE QRTZ_SIMPLE_TRIGGERS
  (
    SCHED_NAME VARCHAR(120) NOT NULL,
    TRIGGER_NAME VARCHAR(200) NOT NULL,
    TRIGGER_GROUP VARCHAR(200) NOT NULL,
    REPEAT_COUNT BIGINT(7) NOT NULL,
    REPEAT_INTERVAL BIGINT(12) NOT NULL,
    TIMES_TRIGGERED BIGINT(10) NOT NULL,
    PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
    FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
        REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
);
CREATE TABLE QRTZ_CRON_TRIGGERS
  (
    SCHED_NAME VARCHAR(120) NOT NULL,
    TRIGGER_NAME VARCHAR(200) NOT NULL,
    TRIGGER_GROUP VARCHAR(200) NOT NULL,
    CRON_EXPRESSION VARCHAR(200) NOT NULL,
    TIME_ZONE_ID VARCHAR(80),
    PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
    FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
        REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
);
CREATE TABLE QRTZ_SIMPROP_TRIGGERS
  (          
    SCHED_NAME VARCHAR(120) NOT NULL,
    TRIGGER_NAME VARCHAR(200) NOT NULL,
    TRIGGER_GROUP VARCHAR(200) NOT NULL,
    STR_PROP_1 VARCHAR(512) NULL,
    STR_PROP_2 VARCHAR(512) NULL,
    STR_PROP_3 VARCHAR(512) NULL,
    INT_PROP_1 INT NULL,
    INT_PROP_2 INT NULL,
    LONG_PROP_1 BIGINT NULL,
    LONG_PROP_2 BIGINT NULL,
    DEC_PROP_1 NUMERIC(13,4) NULL,
    DEC_PROP_2 NUMERIC(13,4) NULL,
    BOOL_PROP_1 VARCHAR(1) NULL,
    BOOL_PROP_2 VARCHAR(1) NULL,
    PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
    FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) 
    REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
);
CREATE TABLE QRTZ_BLOB_TRIGGERS
  (
    SCHED_NAME VARCHAR(120) NOT NULL,
    TRIGGER_NAME VARCHAR(200) NOT NULL,
    TRIGGER_GROUP VARCHAR(200) NOT NULL,
    BLOB_DATA BLOB NULL,
    PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
    FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
        REFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
);
CREATE TABLE QRTZ_CALENDARS
  (
    SCHED_NAME VARCHAR(120) NOT NULL,
    CALENDAR_NAME  VARCHAR(200) NOT NULL,
    CALENDAR BLOB NOT NULL,
    PRIMARY KEY (SCHED_NAME,CALENDAR_NAME)
);
CREATE TABLE QRTZ_PAUSED_TRIGGER_GRPS
  (
    SCHED_NAME VARCHAR(120) NOT NULL,
    TRIGGER_GROUP  VARCHAR(200) NOT NULL, 
    PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP)
);
CREATE TABLE QRTZ_FIRED_TRIGGERS
  (
    SCHED_NAME VARCHAR(120) NOT NULL,
    ENTRY_ID VARCHAR(95) NOT NULL,
    TRIGGER_NAME VARCHAR(200) NOT NULL,
    TRIGGER_GROUP VARCHAR(200) NOT NULL,
    INSTANCE_NAME VARCHAR(200) NOT NULL,
    FIRED_TIME BIGINT(13) NOT NULL,
    PRIORITY INTEGER NOT NULL,
    STATE VARCHAR(16) NOT NULL,
    JOB_NAME VARCHAR(200) NULL,
    JOB_GROUP VARCHAR(200) NULL,
    IS_NONCONCURRENT VARCHAR(1) NULL,
    REQUESTS_RECOVERY VARCHAR(1) NULL,
    PRIMARY KEY (SCHED_NAME,ENTRY_ID)
);
CREATE TABLE QRTZ_SCHEDULER_STATE
  (
    SCHED_NAME VARCHAR(120) NOT NULL,
    INSTANCE_NAME VARCHAR(200) NOT NULL,
    LAST_CHECKIN_TIME BIGINT(13) NOT NULL,
    CHECKIN_INTERVAL BIGINT(13) NOT NULL,
    PRIMARY KEY (SCHED_NAME,INSTANCE_NAME)
);
CREATE TABLE QRTZ_LOCKS
  (
    SCHED_NAME VARCHAR(120) NOT NULL,
    LOCK_NAME  VARCHAR(40) NOT NULL, 
    PRIMARY KEY (SCHED_NAME,LOCK_NAME)
);
The next thing we will do is creating a quartz-ds.xml datasource file (Using JBoss 7.1.1 you can just drop it into the deployments folder. )
<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
  <datasource jndi-name="java:jboss/datasources/quartzDS" pool-name="MySQLPool">
      jdbc:mysql://localhost:3306/quartz
      <driver>mysql-connector-java-5.1.20-bin.jar</driver>
      <pool>
          <max-pool-size>30</max-pool-size>
      </pool>
      <security>
          <user-name>quartz</user-name>
          <password>quartz</password>
      </security>
  </datasource>
</datasources>
Now drop mysql-connector-java-5.1.20-bin.jar as well into the deployments folder:
quartz 2 jboss 7 tutorial
Fine. Now the quartz.properties file:
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
 org.quartz.scheduler.instanceName = MyScheduler
 org.quartz.scheduler.instanceId = AUTO
 #============================================================================
 # Configure ThreadPool
 #============================================================================
 org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
 org.quartz.threadPool.threadCount = 25
 org.quartz.threadPool.threadPriority = 5
 #============================================================================
 # Configure JobStore
 #============================================================================
 org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreCMT
 org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
 org.quartz.jobStore.useProperties = false
 org.quartz.jobStore.dataSource = quartzDS
 org.quartz.jobStore.nonManagedTXDataSource = quartzDSNoTx
 org.quartz.jobStore.tablePrefix = QRTZ_
 org.quartz.jobStore.clusterCheckinInterval = 20000
 org.quartz.jobStore.isClustered = false
 org.quartz.jobStore.acquireTriggersWithinLock=true
 #============================================================================
 # Configure Datasources  
 #============================================================================
 org.quartz.dataSource.quartzDS.jndiURL= java:jboss/datasources/quartzDS
 org.quartz.dataSource.quartzDSNoTx.jndiURL= java:jboss/datasources/quartzDS
This Quartz property file basically sets up a scheduler based on the JobStoreCMT which is meant to be used in an application-server environment that provides container-managed-transactions. We have configured it to acquire connectionxs from the JNDI URL just defined, that is java:jboss/datasources/quartzDS
 
The last trick we need to do is letting the application server read the Quartz properties file: Actually the documentation suggests adding it into the Web application classpath. From my tests however, adding it into WEB-INF/classes suggests that the default quartz.properties are still picked up by JBoss AS.
I finally managed to get it working it by adding it as start up property to the application server (standalone.conf file)
JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxPermSize=256m -Dorg.quartz.properties=/home/quartz/quartz.properties " ...
If you have configured it all correctly you should see the following log from your server, indicating that the JobStoreCMT has been successfully started:
07:29:10,330 INFO  [org.quartz.core.SchedulerSignalerImpl] (http--127.0.0.1-8080
-1) Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
07:29:10,338 INFO  [org.quartz.core.QuartzScheduler] (http--127.0.0.1-8080-1) Quartz Scheduler v.2.0.2 created.
07:29:10,342 INFO  [org.quartz.impl.jdbcjobstore.JobStoreCMT] (http--127.0.0.1-8080-1) Using db table-based data access locking (synchronization).
07:29:10,347 INFO  [org.quartz.impl.jdbcjobstore.JobStoreCMT] (http--127.0.0.1-8080-1) JobStoreCMT initialized.
07:29:10,351 INFO  [org.quartz.core.QuartzScheduler] (http--127.0.0.1-8080-1) Scheduler meta-data: Quartz Scheduler (v2.0.2) 'MyScheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 25 threads.
  Using job-store 'org.quartz.impl.jdbcjobstore.JobStoreCMT' - which supports persistence. and is not clustered.
07:29:10,365 INFO  [org.quartz.impl.StdSchedulerFactory] (http--127.0.0.1-8080-1) Quartz scheduler 'MyScheduler' initialized from default file in current working dir: 'quartz.properties'
07:29:10,370 INFO  [org.quartz.impl.StdSchedulerFactory] (http--127.0.0.1-8080-1) Quartz scheduler version: 2.0.2
That's all! As usual feedback from you is welcome !   
0
0
0
s2sdefault