spring4 + quarz2 集群

阅读更多

1下载:

 def springVersion = "4.2.4.RELEASE";

 

 

    //core spring  

    compile "org.springframework:spring-context:$springVersion"

    compile "org.springframework:spring-core:$springVersion"

    compile "org.springframework:spring-webmvc:$springVersion"

    compile "org.springframework:spring-aop:$springVersion"

   

   

    compile "org.springframework:spring-expression:$springVersion"

    compile "org.springframework:spring-beans:$springVersion"

    compile "org.springframework:spring-aspects:$springVersion"

compile group: 'org.aopalliance', name: 'com.springsource.org.aopalliance', version: '1.0.0'

compile group: 'org.aspectj', name: 'com.springsource.org.aspectj.weaver', version: '1.6.8.RELEASE'

    

 

//定时任务集群

compile group: 'org.quartz-scheduler', name: 'quartz', version: '2.2.1'

compile group: 'org.quartz-scheduler', name: 'quartz-jobs', version: '2.2.1'

 

下载quartz 在docs\dbTables 中可以找到初始化数据库语句。

 

2.建立定时任务:

package task.spring.test;

 

import org.quartz.JobExecutionContext;

import org.quartz.JobExecutionException;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.scheduling.quartz.QuartzJobBean;

 

public class TaskInfoJobEx extends QuartzJobBean{  

    Logger log = LoggerFactory.getLogger(TaskInfoJobEx.class);

 

@Override

protected void executeInternal(JobExecutionContext context) throws JobExecutionException {

 

log.info("=========================我的定时任务===========================------------");

}  

 

 

}

 

 

 

3.设置spring 配置文件:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

 

 

 

   

   

    

 

 

   

           

           

         

         

       

         

         

 

 

 

4.spring-quartz.properties

 

#=============================================================  

#Configure Main Scheduler Properties  

#==============================================================   

org.quartz.scheduler.instanceName = defaultScheduler

org.quartz.scheduler.instanceId = AUTO

 

#==============================================================  

#Configure JobStore  myDS

#============================================================== 

org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate

org.quartz.jobStore.tablePrefix = QRTZ_

#开启簇模式

org.quartz.jobStore.isClustered = true

org.quartz.jobStore.clusterCheckinInterval = 20000  

org.quartz.jobStore.dataSource = myDS

org.quartz.jobStore.maxMisfiresToHandleAtATime = 1

org.quartz.jobStore.misfireThreshold = 120000

#\u9632\u6B62\u9AD8\u8D1F\u8F7D\u548C\u573A\u65F6\u95F4\u4E8B\u7269\u65F6\u9501\u8D85\u65F6

org.quartz.jobStore.txIsolationLevelSerializable = true

 

#==============================================================  

#Configure ThreadPool  

#============================================================== 

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool

##thread count 1-100

org.quartz.threadPool.threadCount = 10

org.quartz.threadPool.threadPriority = 5

org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

 

#==============================================================

#Skip Check Update

#update:true

#not update:false

#==============================================================

org.quartz.scheduler.skipUpdateCheck = true 

 

#============================================================================   

# Configure Plugins    

#============================================================================      

org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin   

org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin

org.quartz.plugin.shutdownhook.cleanShutdown = true

 

 

#============================================================================    

# Configure Datasources      

#============================================================================    

 #数据库配置 

org.quartz.dataSource.myDS.driver =oracle.jdbc.OracleDriver   

org.quartz.dataSource.myDS.URL =jdbc:oracle:thin:@192.168.1.24:1521:dataInstance  

org.quartz.dataSource.myDS.user =shiro    

org.quartz.dataSource.myDS.password =shiro123    

org.quartz.dataSource.myDS.maxConnections = 20  

 

程序 和 数据库初始语句在附件中.

 

注意:如果定时任务集群不是在同一台集群时,需要同步服务的时间。

 

执行结果: 两台机器互斥执行

机器1:
spring4 + quarz2 集群_第1张图片
 

机器2:


spring4 + quarz2 集群_第2张图片
 

 

  • task.zip (2 MB)
  • 下载次数: 0
  • c1dbdf47-4c07-3b47-b901-10810a1662e1.gz (3.2 MB)
  • 下载次数: 0
  • spring4 + quarz2 集群_第3张图片
  • 大小: 131.7 KB
  • spring4 + quarz2 集群_第4张图片
  • 大小: 98 KB
  • 查看图片附件

你可能感兴趣的:(spring4 + quarz2 集群)