WebSphere 集群环境下配置 Quartz集群

 

1. websphere工作管理器引用

    WEB-INF/ibm-web-bnd.xmi

<?xml version="1.0" encoding="UTF-8"?>
<webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1237946146690" virtualHostName="default_host">
  <webapp href="WEB-INF/web.xml#WebApp_1237946146690"/>
    <resRefBindings xmi:id="ResourceRefBinding_1238122581560" jndiName="wm/default">
      <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1238122581560"/>
  </resRefBindings>
 </webappbnd:WebAppBinding>

 

   web.xml

<resource-ref id="ResourceRef_1238122581560">
      <res-ref-name>wm/default</res-ref-name>
      <res-type>commonj.work.WorkManager</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Unshareable</res-sharing-scope>
   </resource-ref>

 

 2. Spring配置

注意: 

  1. dataSource请不要使用Spring注入
  2. job bean需要实现Serializable接口以序列化
<!-- 定义调度器 -->
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
	<property name="triggers">
		<list>
			<ref local="myStatefulJobBean"/>
		</list>
	</property>
	<!--注入事务管理器-->
	<property name="transactionManager" ref="transactionManager"/>
	<!-- 引用配置文件 -->
	<property name="configLocation" value="classpath:conf/quartz.properties"/>
	<!-- 应用WorkManager -->
	<property name="taskExecutor" ref="taskExecutor"></property>
</bean>
<!-- 定义事务引用 -->
<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>
<!--配置使用IBM commonj WorkManager-->
<bean id="taskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
	<property name="workManagerName" value="wm/default"/>
	<property name="resourceRef" value="false"/>
</bean>

<!-- 声明有状态Job-->
<bean id="myStatefulJobBean" class="org.springframework.scheduling.quartz.JobDetailBean">
	<property name="jobClass" value="com.test.quartz.MyStatefulJobBean"/>
</bean>
<!-- 简单触发器 -->
<bean id="hibernateTestTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
	<property name="jobDetail" ref="myStatefulJobBean"/>
	<property name="startDelay">
      		<value>60000</value>
	</property>
    	<property name="repeatInterval">
    		<value>60000</value>
	</property>
</bean>
 

 

job bean

package com.test.quartz;

import java.io.Serializable;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerContext;
import org.quartz.SchedulerException;
import org.quartz.StatefulJob;

import com.achievo.framework.workflow.HibernateSessionEnable;

public class MyStatefulJobBean implements StatefulJob,Serializable{
	
	@HibernateSessionEnable
	public void execute(JobExecutionContext context) throws JobExecutionException {
		String triggerName = context.getTrigger().getName();
		String jobName = context.getJobDetail().getName();
		System.out.println("触发器"+triggerName+"触发作业"+jobName);
	}

}

 

 

3. 配置quartz相关信息

 配置JobStoreCMT 需要两个数据源: 容器管理的数据源 和 JDBC连接数据源

conf/quartz.properties
# Default Properties file for use by StdSchedulerFactory
# to create a Quartz Scheduler Instance, if a different
# properties file is not explicitly specified.
#

org.quartz.scheduler.instanceName = MyClusteredScheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
#org.quartz.scheduler.userTransactionURL=jta/usertransaction

#org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.class = org.springframework.scheduling.quartz.LocalTaskExecutorThreadPool
#org.quartz.threadPool.threadCount = 10
#org.quartz.threadPool.threadPriority = 5
#org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

org.quartz.jobStore.misfireThreshold = 60000

#配置使用数据库存储调度信息 (JobStoreCMT 需要两个数据源)
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreCMT
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 20000
org.quartz.jobStore.dataSource = wasDataSource
org.quartz.jobStore.nonManagedTXDataSource = oracleDS
org.quartz.jobStore.tablePrefix = QRTZ_

#配置容器管理的数据源
org.quartz.dataSource.wasDataSource.jndiURL = java:comp/env/jdbc/oracleDataSource
#org.quartz.dataSource.wasDataSource.java.naming.factory.initial=
#org.quartz.dataSource.wasDataSource.java.naming.provider.url=
#org.quartz.dataSource.wasDataSource.java.naming.security.principal=
#org.quartz.dataSource.wasDataSource.java.naming.security.credentials=

#配置非容器管理的数据源(JDBC数据源)
org.quartz.dataSource.oracleDS.driver = oracle.jdbc.driver.OracleDriver
org.quartz.dataSource.oracleDS.URL = jdbc:oracle:thin:@10.244.150.20:1521:orcl
org.quartz.dataSource.oracleDS.user = oracleuser
org.quartz.dataSource.oracleDS.password = password
org.quartz.dataSource.oracleDS.maxConnections = 5
org.quartz.dataSource.oracleDS.validationQuery = select 0 from dual

 

 4. 创建调度表

在quartz下载目录docs/dbTables 目录下有针对各种数据库的sql script文件

本文使用oracle,所以登录oracle sqlplus 执行 @quartz下载目录/docs/dbTables/tables_oracle.sql

你可能感兴趣的:(oracle,bean,quartz,配置管理,websphere)