spring3.x 与 quartz2.x (JobStoreTX cluster)集群

2 篇文章 0 订阅
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"  
default-lazy-init="true"> 


<!-- 台帐  -->
<bean id="checkAcctJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
    <property name="jobClass" value="com.bestpay.accountsystem.job.quartz.CheckAcctJob"/>
    <property name="durability" value="true" />
</bean>

    <!--
    <bean id="checkAcctJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="checkAcctJob" />
        <property name="targetMethod" value="process" />
        <property name="concurrent" value="false" />
    </bean>
-->
<bean id="checkAcctCronTrigger" class="com.bestpay.accountsystem.job.quartz.PersistableCronTriggerFactoryBean">
    <property name="jobDetail" ref="checkAcctJobDetail" />
    <!--凌晨1点台帐
    <property name="cronExpression" value="0 0 1 * * ?" />
    -->
    <!-- TEST  -->
    <property name="cronExpression" value="0/10 * * * * ?" />

</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="configLocation" value="classpath:quartz.properties" />
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager"/>
    <property name="applicationContextSchedulerContextKey" value="applicationContextKey" />
    <property name="overwriteExistingJobs" value="true"/>
    <property name="jobDetails">
        <list>
            <ref bean="checkAcctJobDetail" />
        </list>
    </property>
    <property name="triggers">
        <list>
        <ref bean="checkAcctCronTrigger" />
        </list>
    </property>
</bean>
</beans>




@Slf4j
@Component("checkAcctJob")
public class CheckAcctJob extends  QuartzJobBean  {

 @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // Process @Autowired injection for the given target object, based on the current web application context.
        <span style="color:#ff0000;">SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);</span>
        log.info("quartz CheckAcctJob start...");
        try {
            process();
        } catch (Exception e) {
           log.error("quartz CheckAcctJob error",e);
        }
    }
}

<span style="color:#ff6666;">CheckAcctJob 中注入用Resource 空指针,用autowrite就可以了。有点奇怪</span>

public class PersistableCronTriggerFactoryBean extends CronTriggerFactoryBean {

    @Override
    public void afterPropertiesSet() {
        super.afterPropertiesSet();

        //Remove the JobDetail element
        getJobDataMap().remove(JobDetailAwareTrigger.JOB_DETAIL_KEY);
    }
}


quartz.properties


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

org.quartz.scheduler.instanceName = MyClusteredScheduler
org.quartz.scheduler.instanceId = AUTO

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

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 25
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.oracle.OracleDelegate
org.quartz.jobStore.useProperties = true
#org.quartz.jobStore.dataSource = myDS
org.quartz.jobStore.tablePrefix = QRTZ_

org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 20000

#============================================================================
# Configure Datasources
#============================================================================

#org.quartz.dataSource.myDS.driver = oracle.jdbc.driver.OracleDriver
#org.quartz.dataSource.myDS.URL = jdbc:oracle:thin:@172.26.7.24:1521:refdb
#org.quartz.dataSource.myDS.user = bpep_acct
#org.quartz.dataSource.myDS.password = acct2014
#org.quartz.dataSource.myDS.maxConnections = 5
#org.quartz.dataSource.myDS.validationQuery=select 0 from dual

maven

<dependency>
				<groupId>org.quartz-scheduler</groupId>
				<artifactId>quartz</artifactId>
				<version>2.1.7</version>
			</dependency>
            <dependency>
                <groupId>org.quartz-scheduler</groupId>
                <artifactId>quartz-oracle</artifactId>
                <version>2.1.7</version>
            </dependency>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值