1. 程式人生 > >quartz定時任務詳解

quartz定時任務詳解

------------------------開始  application-quartz.xml---------------------------------

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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 classpath:org/springframework/beans/factory/xml/spring-beans-4.0.xsd">

    <!-- 總管理類 如果將 lazy-init='false'那麼容器啟動就會執行排程程式  -->
    <bean id="quertzManager" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="true" autowire="no" destroy-method="stop">
        <property name="triggers">
            <array>
                <ref bean="syncCacheTrigger"/>                                
            </array>
        </property>
    </bean>
    
    <bean id="syncCacheTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail" ref="syncCacheTriggerTask"/>
        <property name="cronExpression" value="0 0/3 * * * ?"/>
    </bean>
    <bean id="syncCacheTriggerTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
         <!-- 類 -->
        <property name="targetObject" ref="systemJob"/>
        <!-- 方法名 -->
        <property name="targetMethod" value="syncCacheTriggerTaskJob"/>
        <!-- false=不併發 -->
        <property name="concurrent" value="false" />
    </bean>
        
</beans>
 

------------------------完成  application-quartz.xml---------------------------------

 

語法:

每隔10分鐘:<property name="cronExpression" value="0 0/10 * * * ?"/>

每隔3分鐘:<property name="cronExpression" value="0 0/3 * * * ?"/>

每天早晨5點:<property name="cronExpression" value="0 0 5 * * ?"/>

每天早晨0點:<property name="cronExpression" value="0 0 0 * * ?"/>

每週1凌晨2點:<property name="cronExpression" value="0 0 2 ? * MON"/>

每月1號凌晨2點:<property name="cronExpression" value="0 0 2 1 * ?"/>

每季度1號凌晨2點:<property name="cronExpression" value="0 0 2 1 1,4,7,10 ? *"/>

每年1月1號凌晨2點:<property name="cronExpression" value="0 0 2 1 1 ?"/>

每小時:<property name="cronExpression" value="0 0 0/1 * * ? *"/>

每59分:<property name="cronExpression" value="0 0/59 * * * ?"/>

 

工具網址:https://www.pppet.ne