Quartz Jobstore Management Job

Source: Internet
Author: User

Quartz provides the ramjobstore and JDBC Jobstore two ways to job,ramjobstore the job task into memory, fast, Jobstore in a database management, this article describes the Jobstore mode management job.

When you use the JDBC Jobstore to manage the job, you need to use the following SQL script to establish the appropriate database tables in the database (this article uses MySQL):

DROP table if EXISTS qrtz_fired_triggers;drop table if EXISTS qrtz_paused_trigger_grps;drop table if EXISTS Qrtz_scheduler _state;drop table if EXISTS qrtz_locks;drop table if EXISTS qrtz_simple_triggers;drop table if EXISTS Qrtz_simprop_trigger S;drop table if EXISTS qrtz_cron_triggers;drop table if EXISTS qrtz_blob_triggers;drop table if EXISTS qrtz_triggers;drop Table if EXISTS qrtz_job_details;drop table if EXISTS qrtz_calendars; CREATE TABLE qrtz_job_details (sched_name varchar) NOT NULL, Job_name varchar ($) NOT NULL, Job_group VAR CHAR (+) NOT NULL, DESCRIPTION varchar (+) NULL, Job_class_name varchar () NOT NULL, is_durable varchar (1) Not NULL, is_nonconcurrent varchar (1) is not NULL, Is_update_data varchar (1) is 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) NOT NULL, Trigger_name varchar ($) NOT NULL, Trigger_gRoup varchar ($) NOT NULL, Job_name varchar ($) NOT NULL, Job_group varchar ($) NOT NULL, DESCRIPTION varchar (+) NULL, Next_fire_time BIGINT (+) NULL, Prev_fire_time BIGINT (All) NULL, priority INTEGER NULL, Trigger_sta TE varchar (+) NOT NULL, Trigger_type varchar (8) is not NULL, Start_time BIGINT (all) not NULL, End_time BIGINT (+) NU LL, Calendar_name VARCHAR ($) NULL, MISFIRE_INSTR SMALLINT (2) NULL, Job_data BLOB null, PRIMARY KEY (sched_na Me,trigger_name,trigger_group), FOREIGN KEY (sched_name,job_name,job_group) REFERENCES qrtz_job_details (Sched_na Me,job_name,job_group)); CREATE TABLE qrtz_simple_triggers (sched_name varchar) NOT NULL, Trigger_name varchar ($) NOT NULL, Trigge R_group VARCHAR ($) NOT NULL, Repeat_count BIGINT (7) is not NULL, Repeat_interval BIGINT (+) not NULL, Times_trigge RED BIGINT (Ten) 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) NOT NULL, Trigger_name varchar ($) NOT NULL, Trigger_ GROUP varchar is not NULL, cron_expression varchar ($) NOT NULL, time_zone_id varchar, PRIMARY KEY (sched_ Name,trigger_name,trigger_group), FOREIGN KEY (sched_name,trigger_name,trigger_group) REFERENCES qrtz_triggers (S Ched_name,trigger_name,trigger_group)); CREATE TABLE qrtz_simprop_triggers (sched_name varchar) NOT NULL, Trigger_name varchar ($) NOT NULL , Trigger_group varchar () NOT NULL, str_prop_1 varchar (+) NULL, str_prop_2 varchar (+) NULL, str_prop_3     VARCHAR (+) 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 Varcha R (1) NULL, PRIMARY Key (Sched_name,trigger_name,trigger_group), FOREIGN key (Sched_name,trigger_name,trigger_group) REFERENCES qrtz_t Riggers (Sched_name,trigger_name,trigger_group)); CREATE TABLE qrtz_blob_triggers (sched_name varchar) NOT NULL, Trigger_name varchar ($) NOT NULL, Trigger_ GROUP VARCHAR (+) NOT NULL, Blob_data BLOB null, PRIMARY KEY (sched_name,trigger_name,trigger_group), FOREIGN KE Y (Sched_name,trigger_name,trigger_group) REFERENCES qrtz_triggers (Sched_name,trigger_name,trigger_group)); CREATE TABLE qrtz_calendars (sched_name varchar) NOT NULL, Calendar_name varchar ($) NOT NULL, CALENDAR B LOB not NULL, PRIMARY KEY (sched_name,calendar_name));     CREATE TABLE Qrtz_paused_trigger_grps (sched_name varchar) NOT NULL, Trigger_group varchar (+) NOT NULL, PRIMARY KEY (Sched_name,trigger_group));  CREATE TABLE qrtz_fired_triggers (sched_name varchar) NOT NULL, entry_id varchar (-) NOT NULL, trigger_name VARCHAR(n) not NULL, Trigger_group varchar (+) NOT NULL, instance_name varchar (+) NOT NULL, Fired_time BIGINT (in) N OT null, Sched_time BIGINT (+), priority INTEGER NOT NULL, State varchar (+) NOT NULL, job_name varchar (200) NULL, Job_group varchar ($) NULL, is_nonconcurrent varchar (1) NULL, Requests_recovery varchar (1) NULL, Primar Y KEY (sched_name,entry_id)); CREATE TABLE qrtz_scheduler_state (sched_name varchar) NOT NULL, instance_name varchar ($) NOT NULL, Last_ Checkin_time BIGINT () not NULL, Checkin_interval BIGINT (all) not NULL, PRIMARY KEY (sched_name,instance_name)); CREATE TABLE qrtz_locks (sched_name varchar) NOT NULL, Lock_name varchar (+) NOT NULL, PRIMARY KEY (SCHED _name,lock_name)); commit;

In the SQL script above, quartz related database tables begin with "Qrtz". After establishing the completion table, you need to configure the Quartz quartz.properites file, which is configured as follows:

#instanceName属性可为任何值 [Identify unique instances in JDBC Jobstore, must be the same in all cluster nodes] Org.quartz.scheduler.instanceName = jdbcjobscheduler# Property AUTO, which generates an instance based on host name and timestamp idorg.quartz.scheduler.instanceid= auto# configuration task thread pool Org.quartz.threadPool.class = Org.quartz.simpl.SimpleThreadPoolorg.quartz.threadPool.threadCount = 3org.quartz.threadpool.threadpriority = AA Configuring the JDBC Jobstore storage task Org.quartz.jobStore.misfireThreshold = 60000#org.quartz.jobstore.class = Com.mobile.quartz.store.QJobStoreTxorg.quartz.jobStore.class = Com.mobile.quartz.store.JobStoreTxorg.quartz.jobStore.driverDelegateClass = Org.quartz.impl.jdbcjobstore.StdJDBCDelegateorg.quartz.jobStore.tablePrefix = Qrtz_ Org.quartz.jobStore.useProperties = trueorg.quartz.jobStore.isClustered = True#org.quartz.datasource = c3p0# Org.quartz.dataSource.c3p0.connectionProvider.class =  Com.mobile.quartz.store.JdbcJobStoreConnectionProviderorg.quartz.jobStore.dataSource = MyDS Org.quartz.dataSource.myDS.driver = Com.mysql.jdbc.Driver Org.quartz.dataSource.myDS.URL = Jdbc:mysql://localhoSt:3306/business?useunicode=true&characterencoding=utf-8org.quartz.datasource.myds.user = root Org.quartz.dataSource.myDS.password = root Org.quartz.dataSource.myDS.maxConnections = Ten #配置Quartz      Pluginorg.quartz.plugin.triggHistory.class = Org.quartz.plugins.history.LoggingJobHistoryPlugin Org.quartz.plugin.shutdownhook.class =  Org.quartz.plugins.management.ShutdownHookPluginorg.quartz.plugin.shutdownhook.cleanShutdown = True

Note: When you insert the active trigger information into the Qrtz_fired_triggers table in the Jobstoresupport class in the Quartz 2.21 release, the method Acquirenexttrigger calls

Insertfiredtrigger (conn, nexttrigger, state_acquired, NULL), the last parameter of the method is jobdetail set to null, so the qrtz_fired_triggers table

Jobname,jobgroup information cannot be created, so you can override this method to implement job information writing.

Quartz Jobstore Management Job

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.