[Reprint] quartz cluster configuration

Source: Internet
Author: User
Tags failover
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

  1. Create Table qrtz_job_details
  2. (
  3. Job_name varchar2 (80) not null,
  4. Job_group varchar2 (80) not null,
  5. Description varchar2 (120) null,
  6. Job_class_name varchar2 (128) not null,
  7. Is_durable varchar2 (1) not null,
  8. Is_volatile varchar2 (1) not null,
  9. Is_stateful varchar2 (1) not null,
  10. Requests_recovery varchar2 (1) not null, -- recoverable flag
  11. Job_data blob null,
  12. Primary Key (job_name, job_group)
  13. );

-- Trigger and task Association Table

  1. Create Table qrtz_fired_triggers
  2. (
  3. Entry_id varchar2 (95) not null,
  4. Trigger_name varchar2 (80) not null,
  5. Trigger_group varchar2 (80) not null,
  6. Is_volatile varchar2 (1) not null,
  7. Instance_name varchar2 (80) not null,
  8. Fired_time number (13) not null,
  9. State varchar2 (16) not null,
  10. Job_name varchar2 (80) null,
  11. Job_group varchar2 (80) null,
  12. Is_stateful varchar2 (1) null,
  13. Requests_recovery varchar2 (1) null, -- recoverable flag
  14. Primary Key (entry_id)
  15. );

-- Scheduler status table

  1. Table qrtz_scheduler_state
  2. (
  3. Instance_name varchar2 (80) not null, -- scheduler instance id
  4. Last_checkin_time number (13) not null, -- last check time
  5. Checkin_interval number (13) not null, -- check the interval
  6. Recoverer varchar2 (80) null, -- Restore Scheduler
  7. Primary Key (instance_name)
  8. );

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

 

  1. # The general definition mode of scheduler's main attributes is as follows:
  2. #
  3. # Org. Quartz. scheduler. InstanceName = sched_name
  4. # Org. Quartz. sched_id. instanceid = instance_id
  5. # Org. Quartz. scheduler. threadname = thread_name
  6. # Org. Quartz. scheduler. RMI. Export = false
  7. # Org. Quartz. scheduler. RMI. Proxy = false
  8. # Org. Quartz. scheduler. RMI. registryhost = localhost
  9. # Org. Quartz. schedport. RMI. registryport = 1099
  10. # Org. Quartz. schedstry. RMI. createregistry = never
  11. # Org. Quartz. schedurl. usertransactionurl = user_tx_location
  12. # Org. Quartz. scheduler. wrapjobexecutioninusertransaction = jobs_in_user_tx
  13. # Org. Quartz. schedtime. idlewaittime = idle_wait_time
  14. # Org. Quartz. scheduler. dbfailureretryinterval = db_failure_retry_interval
  15. # Org. Quartz. scheduler. classloadhelper. Class = class_load_helper_class
  16. # 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:

  1. # The general mode for customizing a thread pool is as follows:
  2. #
  3. # Org. Quartz. threadpool. Class = org. Quartz. simpl. simplethreadpool
  4. # Org. Quartz. threadpool. threadcount = thread_count
  5. # Org. Quartz. threadpool. threadpriority = thread_prio
  6. #
  7. # Optional parameters of simplethreadpool:
  8. #
  9. # Org. Quartz. threadpool. makethreadsdaemons = daemon_threads
  10. # Org. Quartz. threadpool. threadsinheritgroupofinitializingthread = inherit_grp
  11. # Org. Quartz. threadpool. threadsinheritcontextclassloaderofinitializingthread = inherit_ldr
  12. #
  13. # Or
  14. #
  15. # Org. Quartz. threadpool. Class = com. mycompany. Goo. foothreadpool
  16. # Org. Quartz. threadpool. somepropoffoothreadpool = somevalue
  17. #

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




  1. #
  2. # The general mode for defining a task storage is as follows:
  3. #
  4. # Org. Quartz. jobstore. Class = org. Quartz. simpl. ramjobstore
  5. # Org. Quartz. jobstore. misfirethreshold = misfire_threshold
  6. #
  7. # Or
  8. #
  9. # Org. Quartz. jobstore. Class = org. Quartz. impl. jdbcjobstore. <jobstoreclass>
  10. # Jobstoreclass is one of the following:
  11. #-Jobstoretx is used for standalone-quartz implementation
  12. #-Jobstorecmt is used to implement quartz Based on appserver-based container-managed transaction.
  13. #
  14. # Org. Quartz. jobstore. driverdelegateclass = org. Quartz. impl. jdbcjobstore. <driverdelegateclass>
  15. # Driverdelegateclass is one of the following:
  16. #-Stdjdbcdelegate (for many JDBC-compliant drivers)
  17. #-Mssqldelegate (for Microsoft SQL Server drivers)
  18. #-Postgresqldelegate (for PostgreSQL drivers)
  19. #-Weblogicdelegate (For WebLogic drivers)
  20. #-Oracle. oracledelegate (for Oracle drivers)
  21. #
  22. # Org. Quartz. jobstore. useproperties = use_properties
  23. # Org. Quartz. jobstore. datasource = ds_name
  24. # Org. Quartz. jobstore. tableprefix = table_prefix
  25. # Org. Quartz. jobstore. isclustered = is_clustered
  26. # Org. Quartz. jobstore. selectwithlocksql = locking_select_statement
  27. # Org. Quartz. jobstore. dontsetautocommitfalse = dont_turn_off_auto_commit
  28. # Org. Quartz. jobstore. maxmisfirestohandleatatime = max_misfire_handle
  29. # Org. Quartz. jobstore. txisolationlevelserializable = serializable_isolation
  30. #
  31. # If you use jobstorecmt, you also need the following parameters:
  32. #
  33. # Org. Quartz. jobstore. nonmanagedtxdatasource = non_managed_tx_ds_name
  34. #
  35. # If you use jobstorecmt, the following parameters are optional:
  36. #
  37. # Org. Quartz. jobstore. dontsetnonmanagedtxconnectionautocommitfalse = dont_turn_off_auto_commit
  38. # Org. Quartz. jobstore. txisolationlevelreadcommitted = read_committed_isolation
  39. #
  40. #
  41. # Alternatively, use a user-defined jobstore to implement:
  42. #
  43. # Org. Quartz. jobstore. Class = com. mycompany. Goo. foojobstore
  44. # Org. Quartz. jobstore. somepropoffoojobstore = somevalue
  45. #
  46. #

The following is a detailed description:

 

3.1.2.4 data source configuration

 

  1. # (JDBC is required only when jdbcjobstore is used, or a plug-in requires JDBC)
  2. # -- 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
  3. #
  4. # The data source definition mode is as follows:
  5. #
  6. # Org. Quartz. datasource. Name. Driver = driver_class_name
  7. # Org. Quartz. datasource. Name. url = db_url
  8. # Org. Quartz. datasource. Name. User = db_user
  9. # Org. Quartz. datasource. Name. Password = db_password
  10. # Org. Quartz. datasource. Name. maxconnections = db_pool_size
  11. # Org. Quartz. datasource. Name. validationquery = validation_query
  12. #
  13. # Or
  14. #
  15. # Org. Quartz. datasource. Name. jndiurl = db_jndi_url
  16. #
  17. # Or
  18. # Org. Quartz. datasource. Name. jndiurl = db_jndi_url
  19. # Org. Quartz. datasource. Name. jndialwayslookup = db_jndi_always_lookup
  20. # Org. Quartz. datasource. Name. java. Naming. Factory. Initial = jndi_ctxt_factory
  21. # Org. Quartz. datasource. Name. java. Naming. provider. url = jndi_provider_url
  22. # Org. Quartz. datasource. Name. java. Naming. Security. Principal = jndi_principal
  23. # Org. Quartz. datasource. Name. java. Naming. Security. Credentials = jndi_credentials
  24. #
  25. #

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

 

  1. # The general schema defined by schedulerplugin is as follows:
  2. #
  3. # Org. Quartz. plugin. Name. Class = plugin_class_name
  4. #
  5. # 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:
  6. #
  7. # Org. Quartz. plugin. Name. propname = propvalue
  8. #
  9. #... "Propname" has a "setpropname" method in the plug-in class, but only the original data type (including strings) is supported ).
  10. #

A simple example of plug-in Configuration:

  1. Org. Quartz. plugin. trigghistory. Class = org. Quartz. plugins. History. loggingtriggerhistoryplugin
  2. Org. quartz. plugin. trigghistory. triggerfiredmessage = trigger {1 }. {0} fired job {6 }. {5} at: {4, date, HH: mm: SS mm/DD/YYYY}
  3. 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}
  4.  
  5. Org. Quartz. plugin. jobinitializer. Class = org. Quartz. plugins. xml. jobinitializationplugin
  6. Org. Quartz. plugin. jobinitializer. filename = data/my_job_data.xml
  7. Org. Quartz. plugin. jobinitializer. overwriteexistingjobs = false
  8. Org. Quartz. plugin. jobinitializer. failonfilenotfound = true
  9.  
  10. Org. Quartz. plugin. shutdownhook. Class = org. Quartz. plugins. Management. shutdownhookplugin
  11. Org. Quartz. plugin. shutdownhook. cleanshutdown = true

3.1.3 example

  1. #===================================================== ==================================
  2. # Configure main scheduler Properties
  3. #===================================================== ================================
  4.  
  5. Org. Quartz. scheduler. InstanceName = myclusteredscheduler
  6. Org. Quartz. schedid. instanceid = auto
  7.  
  8. #===================================================== ================================
  9. # Configure threadpool
  10. #===================================================== ================================
  11.  
  12. Org. Quartz. threadpool. Class = org. Quartz. simpl. simplethreadpool
  13. Org. Quartz. threadpool. threadcount = 25
  14. Org. Quartz. threadpool. threadpriority = 5
  15.  
  16. #===================================================== ================================
  17. # Configure jobstore
  18. #===================================================== ================================
  19.  
  20. Org. Quartz. jobstore. misfirethreshold = 60000
  21.  
  22. Org. Quartz. jobstore. Class = org. Quartz. impl. jdbcjobstore. jobstoretx
  23. Org. Quartz. jobstore. driverdelegateclass = org. Quartz. impl. jdbcjobstore. Oracle. oracledelegate
  24. Org. Quartz. jobstore. useproperties = false
  25. Org. Quartz. jobstore. datasource = myds
  26. Org. Quartz. jobstore. tableprefix = qrtz _
  27.  
  28. Org. Quartz. jobstore. isclustered = true
  29. Org. Quartz. jobstore. clustercheckininterval = 20000
  30.  
  31. #===================================================== ================================
  32. # Configure datasources
  33. #===================================================== ================================
  34.  
  35. Org. Quartz. datasource. myds. Driver = oracle. JDBC. Driver. oracledriver
  36. Org. Quartz. datasource. myds. url = JDBC: oracle: thin: @ cluster: 1521: Dev
  37. Org. Quartz. datasource. myds. User = quartz
  38. Org. Quartz. datasource. myds. Password = quartz
  39. Org. Quartz. datasource. myds. maxconnections = 5
  40. Org. Quartz. datasource. myds. validationquery = select 0 from dual

View Part 1: http://gocom.primeton.com/modules/newbb/forumtopic19180_9937_40.htm

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.