Java,quartz定时任务


jar依赖包


quartz-context.xml配置文件



<?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:p="http://www.springframework.org/schema/p"
    xmlns:c="http://www.springframework.org/schema/c" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- ===========================配置Scheduler========================= -->
    <!-- 配置SchedulerFactoryBean -->
    <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="overwriteExistingJobs" value="true" />
        <property name="autoStartup" value="true" />
        <property name="configLocation" value="classpath:quartz.properties" />
        <property name="applicationContextSchedulerContextKey" value="applicationContext" />
        <property name="jobFactory">
              <bean class="com.aifa.project.nonbank.client.support.ScheduleQuartzJobBeanFactorySupport" />
          </property>
        <property name="triggers">
            <list>
                <ref bean="billCreateScheduleCronTrigger" />
            </list>
        </property>
    </bean>

    <!-- ===========================配置Scheduler========================= -->
    <!-- 账单生成定时任务jobDetail -->
    <bean id="billCreateScheduleJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="jobClass" value="com.aifa.project.nonbank.client.schedule.BillCreateSchedule" />  
        <property name="name" value="billCreateSchedule" />  
        <property name="durability" value="true" />
    </bean>
    <!-- 账单生成定时任务任务cronTrigger 每个月的一号一点触发-->
    <bean id="billCreateScheduleCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail"><ref bean="billCreateScheduleJobDetail" /></property>
        <property name="cronExpression"><value>0 0 1 1 * ?</value></property>
    </bean>
    
</beans>


定时任务触发调用的类

package com.aifa.project.nonbank.client.schedule;

import java.util.Date;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.aifa.core.support.DateSupport;
import com.aifa.core.support.LoggerSupport;
import com.aifa.project.nonbank.core.service.BillGenerationService;
import com.aifa.project.nonbank.core.service.OriginDataElecGovCenterLoaderService;
import com.aifa.project.nonbank.core.service.QueryRecordService;

/**
 * 账单生成定时任务
 * @author guangwen zhou
 *
 */

public class BillCreateSchedule extends QuartzJobBean {
    
    /**
     * 日志对象
     */
    @Autowired
    private LoggerSupport logger;
    
    /**
     * 日期支撑类
     */
    @Autowired
    private DateSupport dateSupport;
    
    /**
     * 账单生成服务对象
     */
    @Autowired
    private BillGenerationService billGenerationService;
    
    

    @Override
    protected void executeInternal(JobExecutionContext arg0)throws JobExecutionException {
        logger.debug(">>定时生成账单任务 启动:"+dateSupport.formatCharacter(dateSupport.getSystemDate(),"yyyy-MM-dd HH:mm:ss"));
        try {

            //这里调用具体的业务方法即可

            billGenerationService.createBill();
        } catch (Exception e) {
            logger.error(">>定时生成申请结果任务异常", e);
        }
        logger.debug(">>定时生成账单任务 完成:"+dateSupport.formatCharacter(dateSupport.getSystemDate(),"yyyy-MM-dd HH:mm:ss"));
    }

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值