<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> <!-- ############################ 批量删除空库存数据 ########################## --> <bean id="batchDelEmptyStoreQuantJob" class="com.yundaex.wms.sys.job.TimingBatchDelEmptyStoreQuantJob"></bean> <bean id="batchDelEmptyStoreQuantJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="batchDelEmptyStoreQuantJob" /> <property name="targetMethod" value="doExecute" /> <property name="concurrent" value="false"/><!-- 此定时任务不会并发,CronTriggerBean任务执行超时,会等到下次执行。quartz采用多线程,其它定时任务不受此定时任务影响--> </bean> <bean id="batchDelEmptyStoreQuantDoTime" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="batchDelEmptyStoreQuantJobTask" /> <!-- cron表达式 --> <property name="cronExpression" value="0 0 02 * * ?" /><!-- 每天凌晨2点执行一次--> </bean> <!-- ############################ 批量删除僵化包装台数据 ########################## --> <bean id="batchDelZombiePackBenchNoJob" class="com.yundaex.wms.core.alive.job.TimingBatchDelZombiePackBenchNoJob"></bean> <bean id="batchDelZombiePackBenchNoJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="batchDelZombiePackBenchNoJob" /> <property name="targetMethod" value="doExecute" /> <property name="concurrent" value="false"/><!-- 此定时任务不会并发,SimpleTriggerBean任务执行超时,执行完立即再次执行--> </bean> <bean id="batchDelZombiePackBenchNoDoTime" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> <property name="jobDetail" ref="batchDelZombiePackBenchNoJobTask" /> <property name="repeatInterval" value="40000"></property><!-- 每40000毫秒执行一次--> </bean> <!-- ############################ 定时处理「待取消」电子面单 ########################## --> <bean id="batchCancelElectronOrderJob" class="com.yundaex.wms.sys.job.TimingBatchCancelElectronOrderJob"></bean> <bean id="batchCancelElectronOrderJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="batchCancelElectronOrderJob" /> <property name="targetMethod" value="doExecute" /> <property name="concurrent" value="false"/> </bean> <bean id="batchCancelElectronOrderDoTime" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="batchCancelElectronOrderJobTask" /> <!-- cron表达式 --> <property name="cronExpression" value="0 0/3 * * * ?" /><!-- 每3分钟执行一次--> </bean> <!-- ############################ 发货信息和揽件扫描信息的数据接口job ########################## --> <bean id="deliveryAndPiecesInfoGettingJob" class="com.yundaex.wms.sys.job.DeliveryAndPiecesInfoGettingJob"></bean> <bean id="deliveryAndPiecesInfoGettingJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="deliveryAndPiecesInfoGettingJob" /> <property name="targetMethod" value="doExecute" /> <property name="concurrent" value="false"/> </bean> <bean id="deliveryAndPiecesInfoGettingJobDoTime" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="deliveryAndPiecesInfoGettingJobTask" /> <!-- cron表达式 --> <property name="cronExpression" value="0 */30 * * * ?" /><!-- 每30分钟执行一次--> </bean> <!-- ############################ 定时数据归档 ########################## --> <bean id="autoArchiveJob" class="com.yundaex.wms.sys.job.AutoArchiveJob"></bean> <bean id="autoArchiveJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="autoArchiveJob" /> <property name="targetMethod" value="doExecute" /> <property name="concurrent" value="false"/> </bean> <bean id="autoArchiveDoTime" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="autoArchiveJobTask" /> <!-- cron表达式 --> <property name="cronExpression" value="0 0 03 * * ?" /><!-- 每天凌晨3点执行一次--> </bean> <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 --> <bean id="startQuartz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="batchDelEmptyStoreQuantDoTime"/> <ref bean="batchDelZombiePackBenchNoDoTime"/> <ref bean="batchCancelElectronOrderDoTime"/> <ref bean="deliveryAndPiecesInfoGettingJobDoTime"/> <ref bean="autoArchiveDoTime"/> </list> </property> </bean> </beans>
import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import com.yundaex.wms.core.alive.job.handler.BatchDelZombiePackBenchNoHandler; public class TimingBatchDelZombiePackBenchNoJob { private static final Logger logger = Logger.getLogger(TimingBatchDelZombiePackBenchNoJob.class); @Autowired private BatchDelZombiePackBenchNoHandler handler; public void doExecute() { try { long startTime = 0L; if (logger.isDebugEnabled()){ startTime = System.currentTimeMillis(); logger.debug("定时清除僵化包装台任务开始。"); } handler.execute(); if (logger.isDebugEnabled()){ long endTime = System.currentTimeMillis(); logger.debug("定时清除僵化包装台任务结束,耗时:" + (endTime - startTime) + "毫秒。"); } } catch (Exception e) { logger.error("定时清除僵化包装台任务异常。", e); } } }
<!-- TIMER --> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>1.8.5</version> </dependency>