日期:2014-05-16  浏览次数:20553 次

Quartzs -- JDBC-JobStore - Oracle 实现 + Cluster
  • 数据库

从%QUARTZ_HOME%/docs/dbTables中找对应的oracle脚本文件tables_oracle.sql。

在对应的quartz前缀前加上前缀TEST_

注:有两个INDEX的名字将超过30而报错。

  • 相关文件结构

Quartz(project name)

?|-src

???? |-com.siyuan.test.quartz.conf

????????? |-quartz.xml

???? |-com.siyuan.test.quartz.job

????????? |-LogJob.java

???? |-frameworkx.springframework.scheduling.quartz

????????? |-BeanInvokingJobDetailFactoryBean.java

????????? |-MethodInvokingJobDetailFactoryBean.java

???? |-quartz.properties

???? |-quartz.sql

?|-WebContent

???? |-WEB-INF

????????? |-web.xml

  • 相关文件

1)LogJob.java :必须实现java.io.Serializable

?

/**
 * LogJob.java
 *
 * Created on Sep 13, 2011, 11:41:00 AM
 * Copyright (c) 2001-2008 by G2X, Inc. All Rights Reserved.
 */
package com.siyuan.test.quartz.job;

import java.io.Serializable;

/**
 * This class
 *
 * @author Carro.zhu
 * @version $Revision$, $Date$, $Author$, $Name$
 */
public class LogJob implements Serializable{

 public void execute() {
  System.out.println("LogJob.execute : " + System.currentTimeMillis());
 }

}

?

2)quartz.xml

必须使用frameworkx.springframework.scheduling.quartz.BeanInvokingJobDetailFactoryBean

或者frameworkx.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean,

直接使用org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean会报java.io.NotSerializableException异常,参考http://jira.springframework.org/browse/SPR-3797

?

shouldRecover 当Quartz服务被中止后,再次启动或集群中其他机器接手任务时会尝试恢复执行之前未完成的所有任务

?

overwriteExistingJobs 必须设置为TRUE,否则配置文件中的更新无法影响DB已存在的信息

通过NAME和GROUP识别

?

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

	<bean name="job" class="com.siyuan.test.quartz.job.LogJob"></bean>
	
	<bean name="jobDetail"
		class="frameworkx.springframework.scheduling.quartz.BeanInvokingJobDetailFactoryBean">
		<property name="targetBean" value="job" />
		<property name="targetMethod" value="execute" />
		<property name="group" value="scheduler" />
		<!-- 
		<property name="shouldRecover" value="true" />
		 -->
	</bean>
	
    <bean name="trigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="jobDetail" />
        <property name="cronExpression" value="0/2 * * * * ?" />
        <property name="name" value="trigger" />
        <property name="group" value="scheduler" />
    </bean>
	
	<bean name="scheduler"
		class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref bean="trigger" />
			</list>
		</property>
		<prope