Quartzs实现任务调度 及对cron时间的编写调试

配置QuartzsSpring.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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
">
    <!-- 该配置为预留,现阶段并没有过真正使用  -->
    <!-- 自动扫描com.synchro.platform.quartz下的所有类,使其解释为定时任务类 -->
    <context:component-scan base-package="com.webcarrier.iframework.quartz" />
    
    <bean id="syncOrderDetail"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="orderQuartz" />
        <property name="targetMethod" value="syncOrderStatQuartz" />
        <!-- 禁止并发执行 -->
        <property name="concurrent" value="false" />
    </bean>
    <bean id="syncOrderCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="syncOrderDetail" />
        <!-- 每隔1分钟触发一次 value="0 0/1 * * * ?"-->
        <property name="cronExpression" value="0/12 * * * * ? *" />
    </bean>
    <bean id="schedulerFactory"
        class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="syncOrderCronTrigger" />
            </list>
        </property>
    </bean>

</beans>


实现类

package com.webcarrier.iframework.quartz;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/*import com.imengrui.vims.Interface.service.OrderOpsService;
import com.imengrui.vims.util.PropertiesUtil;*/

@Component(value = "orderQuartz")
public class OrderQuartz {
    /*@Autowired
    private OrderOpsService orderOpsService;*/
        
        private final Logger logger = Logger.getLogger(OrderQuartz.class);    
        public void syncOrderStatQuartz() {
            
            /* 是否进行定时任务
            String superIs = PropertiesUtil.getValue("super.is");
            
            if (!"yes".equals(superIs))
                
                return;*/
            SimpleDateFormat sm=new SimpleDateFormat("yyyyMMddHHmmssss");
            String format = sm.format(new Date());
            System.out.println(format);                
            logger.info("OrderQuartz------start");

            try {
                //orderOpsService.batchSyncOrderStat();
                System.out.println("ok");
            } catch (Exception e) {
                e.printStackTrace();
                logger.info("OrderQuartz------error");
            }

            logger.info("OrderQuartz------end");
        }        
    }




对cron时间的编写调试















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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值