quartz 分布式配置

来源:互联网 发布:阿里云手机云空间 编辑:程序博客网 时间:2024/05/16 07:21

1.背景

当quartz部署在分布式环境下时,希望同一时刻同一个job只运行在一个节点上。

2.模拟场景 工程目录下 有job1 job2 job3 分别部署在 node1 node2 node3上。

不采用分布式集群时 在每个节点 job1 job2 job3都执行。node1 同时执行三个job node2同时执行三个job node3同时执行三个job。(共9个job在执行。)

采用分布式集群配置后 job1 job2 job3 在这三个节点同一时刻一共有job1 job2 job3在执行。共三个job执行。

3分布式配置方式(持久化到数据库中支持主流数据库mysql为例)

1.官网下载quartz-2.2.2.jar 解压。

docs\dbTables 目录下找到 tables_mysql.sql 执行在自己的mysql中。


2创建java普通工程。

依赖包lib下

c3p0-0.9.1.1.jar

log4j-1.2.16.jar

quartz-2.2.2.jar

quartz-jobs-2.2.2.jar

slf4j-api-1.7.7.jar

slf4j-log4j12-1.7.7.jar


3 配置quartz.properties

examples\example13\instance1.properties 改名quartz.properties 拷贝到工程src目录下

#============================================================================
# Configure Main Scheduler Properties  
#============================================================================


org.quartz.scheduler.instanceName: TestScheduler
org.quartz.scheduler.instanceId: instance_one


org.quartz.scheduler.skipUpdateCheck: true


#============================================================================
# Configure ThreadPool  
#============================================================================


org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 5
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.StdJDBCDelegate
org.quartz.jobStore.useProperties=false
org.quartz.jobStore.dataSource=myDS
org.quartz.jobStore.tablePrefix=QRTZ_
org.quartz.jobStore.isClustered=true


#============================================================================
# Other Example Delegates
#============================================================================
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DB2v6Delegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DB2v7Delegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.DriverDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.HSQLDBDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.MSSQLDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PointbaseDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.WebLogicDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
#org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.oracle.WebLogicOracleDelegate


#============================================================================
# Configure Datasources  
#============================================================================
org.quartz.dataSource.myDS.driver:com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL: jdbc:mysql://localhost:3306/quartz
org.quartz.dataSource.myDS.user: root
org.quartz.dataSource.myDS.password: root
org.quartz.dataSource.myDS.maxConnections: 5
org.quartz.dataSource.myDS.validationQuery: select 0
#============================================================================
# Configure Plugins 
#============================================================================


#org.quartz.plugin.shutdownHook.class: org.quartz.plugins.management.ShutdownHookPlugin
#org.quartz.plugin.shutdownHook.cleanShutdown: true




#org.quartz.plugin.triggHistory.class: org.quartz.plugins.history.LoggingJobHistoryPlugin

4 把examples\example13\log4j.xml 放在src目录下


就这么简单大功告成!!qq:263090670 有问题可以交流.


0 0
原创粉丝点击