1. Basic Information
Abstract:Quartz is an open-source job scheduling framework. It is fully written in Java and designed for j2se and J2EE applications. It provides great flexibility without sacrificing simplicity. You can use it to create simple or complex scheduling for executing a job. It has many features, such as database support, clusters, plug-ins, pre-Build of EJB jobs, javamail and others, and supports Cron-like expressions. Cluster configuration is generally complicated. How do I configure the Cluster Features in quartz?
Author: Wu yuhou
View Part 2: http://gocom.primeton.com/modules/newbb/forumtopic19180_9963_40.htm
2 quartz cluster configuration
Quartz is an open-source job scheduling framework. It is fully written in Java and designed for j2se and J2EE applications. It provides great flexibility without sacrificing simplicity. You can use it to create simple or complex scheduling for executing a job. It has many features, such as database support, clusters, plug-ins, pre-Build of EJB jobs, javamail and others, and supports Cron-like expressions. Cluster configuration is generally complicated. How do I configure the Cluster Features in quartz?
2.1 Basic Principles of Cluster implementation
Currently, the latest version of quartz is 1.6.0. Quartz manages clusters by Using relational databases and JDBC job storage.
1. Principle
Through failover and load balancing, the cluster can bring high availability and scalability to the scheduler. Currently, clusters can only work in the JDBC-jobstore (jobstoretx or jobstorecmt) mode. In essence, it enables each node on the cluster to work by sharing the same database (quartz manages the cluster by starting two maintenance threads to maintain the database status, and one is to detect the node status thread, one is the restoration task thread ).
Load Balancing is automatically completed, and each node in the cluster will trigger the task as soon as possible. When the trigger time is reached, the first node will obtain the task (by locking) and become the node for executing the task.
Failover occurs when one or more tasks fail to be executed on a node. When a node fails, other nodes detect the database tasks that are being performed on the failed node. Any task marked as recoverable (the "Requests recovery" attribute of task details) will be re-executed by other nodes. A task that does not mark as recoverable will only be released and will be executed when the trigger is triggered next time.
2. Tables Used for cluster management
-- Task Details table
- Create Table qrtz_job_details
- (
- Job_name varchar2 (80) not null,
- Job_group varchar2 (80) not null,
- Description varchar2 (120) null,
- Job_class_name varchar2 (128) not null,
- Is_durable varchar2 (1) not null,
- Is_volatile varchar2 (1) not null,
- Is_stateful varchar2 (1) not null,
- Requests_recovery varchar2 (1) not null, -- recoverable flag
- Job_data blob null,
- Primary Key (job_name, job_group)
- );
-- Trigger and task Association Table
- Create Table qrtz_fired_triggers
- (
- Entry_id varchar2 (95) not null,
- Trigger_name varchar2 (80) not null,
- Trigger_group varchar2 (80) not null,
- Is_volatile varchar2 (1) not null,
- Instance_name varchar2 (80) not null,
- Fired_time number (13) not null,
- State varchar2 (16) not null,
- Job_name varchar2 (80) null,
- Job_group varchar2 (80) null,
- Is_stateful varchar2 (1) null,
- Requests_recovery varchar2 (1) null, -- recoverable flag
- Primary Key (entry_id)
- );
-- Scheduler status table
- Table qrtz_scheduler_state
- (
- Instance_name varchar2 (80) not null, -- scheduler instance id
- Last_checkin_time number (13) not null, -- last check time
- Checkin_interval number (13) not null, -- check the interval
- Recoverer varchar2 (80) null, -- Restore Scheduler
- Primary Key (instance_name)
- );
2.2 cluster configuration
Activate the cluster feature by setting the "org. Quartz. jobstore. isclustered" attribute to "true. Each instance in the cluster must have a unique "instance id" ("org. quartz. scheduler. instanceid "attribute), but the same" scheduler Instance name "(" org. quartz. scheduler. instancename "), that is, every instance in the cluster must use the same quartz. properties configuration file. Except the following, the content of the configuration file must be the same:
? Different thread pool sizes,
? Different "org. Quartz. schedid. instanceid" attribute values (which can be easily set to "Auto ).
? Note: Never run clusters on different machines unless their clock is running very regularly using some form of Synchronization Service (Daemon) (the clock must be within 1 minute 1 second) to achieve synchronization. Also, do not trigger a non-cluster instance if other instances are running on the same database table. You will cause serious corrosion of your data and unexpected behavior.
? For more information, see the quartz configuration file in the appendix.
3 appendix
3.1 quartz configuration file description
3.1.1 basic description of quartz configuration file
File Name: the default file name quartz. properties. You can modify the system property org. Quartz. properties to load the custom configuration.
Format: Property File
3.1.2 detailed description of quartz configuration file
3.1.2.1 configure the main attributes of Scheduler
- # The general definition mode of scheduler's main attributes is as follows:
- #
- # Org. Quartz. scheduler. InstanceName = sched_name
- # Org. Quartz. sched_id. instanceid = instance_id
- # Org. Quartz. scheduler. threadname = thread_name
- # Org. Quartz. scheduler. RMI. Export = false
- # Org. Quartz. scheduler. RMI. Proxy = false
- # Org. Quartz. scheduler. RMI. registryhost = localhost
- # Org. Quartz. schedport. RMI. registryport = 1099
- # Org. Quartz. schedstry. RMI. createregistry = never
- # Org. Quartz. schedurl. usertransactionurl = user_tx_location
- # Org. Quartz. scheduler. wrapjobexecutioninusertransaction = jobs_in_user_tx
- # Org. Quartz. schedtime. idlewaittime = idle_wait_time
- # Org. Quartz. scheduler. dbfailureretryinterval = db_failure_retry_interval
- # Org. Quartz. scheduler. classloadhelper. Class = class_load_helper_class
- # Org. Quartz. Context. Key. some_key = some_value
The following is a detailed description:
3.1.2.2 threadpool Configuration
The following is a detailed description:
- # The general mode for customizing a thread pool is as follows:
- #
- # Org. Quartz. threadpool. Class = org. Quartz. simpl. simplethreadpool
- # Org. Quartz. threadpool. threadcount = thread_count
- # Org. Quartz. threadpool. threadpriority = thread_prio
- #
- # Optional parameters of simplethreadpool:
- #
- # Org. Quartz. threadpool. makethreadsdaemons = daemon_threads
- # Org. Quartz. threadpool. threadsinheritgroupofinitializingthread = inherit_grp
- # Org. Quartz. threadpool. threadsinheritcontextclassloaderofinitializingthread = inherit_ldr
- #
- # Or
- #
- # Org. Quartz. threadpool. Class = com. mycompany. Goo. foothreadpool
- # Org. Quartz. threadpool. somepropoffoothreadpool = somevalue
- #
View Part 2: http://gocom.primeton.com/modules/newbb/forumtopic19180_9963_40.htm
Reference: http://gocom.primeton.com/modules/newbb/item43467_43467.htm? Referer = csdn & utm_campaign = gocomoncsdn & utm_source = csdn & utm_medium = csdnzone
Basic Information
Abstract: quartz is an open-source job scheduling framework fully written in Java and designed for j2se and J2EE applications. It provides great flexibility without sacrificing simplicity. You can use it to create simple or complex scheduling for executing a job. It has many features, such as database support, clusters, plug-ins, pre-Build of EJB jobs, javamail and others, and supports Cron-like expressions. Cluster configuration is generally complicated. How do I configure the Cluster Features in quartz?
Author: Wu yuhou
View Part 1: http://gocom.primeton.com/modules/newbb/forumtopic19180_9937_40.htm
3.1.2.3 job store configuration
- #
- # The general mode for defining a task storage is as follows:
- #
- # Org. Quartz. jobstore. Class = org. Quartz. simpl. ramjobstore
- # Org. Quartz. jobstore. misfirethreshold = misfire_threshold
- #
- # Or
- #
- # Org. Quartz. jobstore. Class = org. Quartz. impl. jdbcjobstore. <jobstoreclass>
- # Jobstoreclass is one of the following:
- #-Jobstoretx is used for standalone-quartz implementation
- #-Jobstorecmt is used to implement quartz Based on appserver-based container-managed transaction.
- #
- # Org. Quartz. jobstore. driverdelegateclass = org. Quartz. impl. jdbcjobstore. <driverdelegateclass>
- # Driverdelegateclass is one of the following:
- #-Stdjdbcdelegate (for many JDBC-compliant drivers)
- #-Mssqldelegate (for Microsoft SQL Server drivers)
- #-Postgresqldelegate (for PostgreSQL drivers)
- #-Weblogicdelegate (For WebLogic drivers)
- #-Oracle. oracledelegate (for Oracle drivers)
- #
- # Org. Quartz. jobstore. useproperties = use_properties
- # Org. Quartz. jobstore. datasource = ds_name
- # Org. Quartz. jobstore. tableprefix = table_prefix
- # Org. Quartz. jobstore. isclustered = is_clustered
- # Org. Quartz. jobstore. selectwithlocksql = locking_select_statement
- # Org. Quartz. jobstore. dontsetautocommitfalse = dont_turn_off_auto_commit
- # Org. Quartz. jobstore. maxmisfirestohandleatatime = max_misfire_handle
- # Org. Quartz. jobstore. txisolationlevelserializable = serializable_isolation
- #
- # If you use jobstorecmt, you also need the following parameters:
- #
- # Org. Quartz. jobstore. nonmanagedtxdatasource = non_managed_tx_ds_name
- #
- # If you use jobstorecmt, the following parameters are optional:
- #
- # Org. Quartz. jobstore. dontsetnonmanagedtxconnectionautocommitfalse = dont_turn_off_auto_commit
- # Org. Quartz. jobstore. txisolationlevelreadcommitted = read_committed_isolation
- #
- #
- # Alternatively, use a user-defined jobstore to implement:
- #
- # Org. Quartz. jobstore. Class = com. mycompany. Goo. foojobstore
- # Org. Quartz. jobstore. somepropoffoojobstore = somevalue
- #
- #
The following is a detailed description:
3.1.2.4 data source configuration
- # (JDBC is required only when jdbcjobstore is used, or a plug-in requires JDBC)
- # -- If your scheduler is very busy, for example, if you want to execute the same number of tasks in a certain thread pool, you should set the number of connections of the data source to the number of threads + 1
- #
- # The data source definition mode is as follows:
- #
- # Org. Quartz. datasource. Name. Driver = driver_class_name
- # Org. Quartz. datasource. Name. url = db_url
- # Org. Quartz. datasource. Name. User = db_user
- # Org. Quartz. datasource. Name. Password = db_password
- # Org. Quartz. datasource. Name. maxconnections = db_pool_size
- # Org. Quartz. datasource. Name. validationquery = validation_query
- #
- # Or
- #
- # Org. Quartz. datasource. Name. jndiurl = db_jndi_url
- #
- # Or
- # Org. Quartz. datasource. Name. jndiurl = db_jndi_url
- # Org. Quartz. datasource. Name. jndialwayslookup = db_jndi_always_lookup
- # Org. Quartz. datasource. Name. java. Naming. Factory. Initial = jndi_ctxt_factory
- # Org. Quartz. datasource. Name. java. Naming. provider. url = jndi_provider_url
- # Org. Quartz. datasource. Name. java. Naming. Security. Principal = jndi_principal
- # Org. Quartz. datasource. Name. java. Naming. Security. Credentials = jndi_credentials
- #
- #
The preceding figure shows two data source definitions: a data source can be created with the given database connection information, or the logical ing of the JNDI data source generated by the Application Server Management.
The following is a detailed description:
3.1.2.5 configure sched INS
- # The general schema defined by schedulerplugin is as follows:
- #
- # Org. Quartz. plugin. Name. Class = plugin_class_name
- #
- # If this plug-in class has some attribute values that need to be set through the "setter" method, the attributes of the name and value are defined as follows:
- #
- # Org. Quartz. plugin. Name. propname = propvalue
- #
- #... "Propname" has a "setpropname" method in the plug-in class, but only the original data type (including strings) is supported ).
- #
A simple example of plug-in Configuration:
- Org. Quartz. plugin. trigghistory. Class = org. Quartz. plugins. History. loggingtriggerhistoryplugin
- Org. quartz. plugin. trigghistory. triggerfiredmessage = trigger {1 }. {0} fired job {6 }. {5} at: {4, date, HH: mm: SS mm/DD/YYYY}
- Org. quartz. plugin. trigghistory. triggercompletemessage = trigger {1 }. {0} completed firing job {6 }. {5} At {4, date, HH: mm: SS mm/DD/YYYY} with resulting trigger instruction code: {9}
-
- Org. Quartz. plugin. jobinitializer. Class = org. Quartz. plugins. xml. jobinitializationplugin
- Org. Quartz. plugin. jobinitializer. filename = data/my_job_data.xml
- Org. Quartz. plugin. jobinitializer. overwriteexistingjobs = false
- Org. Quartz. plugin. jobinitializer. failonfilenotfound = true
-
- Org. Quartz. plugin. shutdownhook. Class = org. Quartz. plugins. Management. shutdownhookplugin
- Org. Quartz. plugin. shutdownhook. cleanshutdown = true
3.1.3 example
- #===================================================== ==================================
- # Configure main scheduler Properties
- #===================================================== ================================
-
- Org. Quartz. scheduler. InstanceName = myclusteredscheduler
- Org. Quartz. schedid. 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. misfirethreshold = 60000
-
- Org. Quartz. jobstore. Class = org. Quartz. impl. jdbcjobstore. jobstoretx
- Org. Quartz. jobstore. driverdelegateclass = org. Quartz. impl. jdbcjobstore. Oracle. oracledelegate
- Org. Quartz. jobstore. useproperties = false
- Org. Quartz. jobstore. datasource = myds
- Org. Quartz. jobstore. tableprefix = qrtz _
-
- Org. Quartz. jobstore. isclustered = true
- Org. Quartz. jobstore. clustercheckininterval = 20000
-
- #===================================================== ================================
- # Configure datasources
- #===================================================== ================================
-
- Org. Quartz. datasource. myds. Driver = oracle. JDBC. Driver. oracledriver
- Org. Quartz. datasource. myds. url = JDBC: oracle: thin: @ cluster: 1521: Dev
- Org. Quartz. datasource. myds. User = quartz
- Org. Quartz. datasource. myds. Password = quartz
- Org. Quartz. datasource. myds. maxconnections = 5
- Org. Quartz. datasource. myds. validationquery = select 0 from dual
View Part 1: http://gocom.primeton.com/modules/newbb/forumtopic19180_9937_40.htm