Talking about spring Integrating Quatz

Keywords: PHP Spring Java xml encoding

Use spring 3.0.6 + quartz 1.8.6

The xml is as follows

<?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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd">
 
    <!-- Task 1 Configuration -->
    <bean name="job1" class="com.quartz.demo.Job1Demo"/>
    <bean id="jobDetail_1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- Execution Class -->
        <property name="targetObject">
            <ref bean="job1" />
        </property>
        <!-- Methods in Classes -->
        <property name="targetMethod">
            <value>sayHello</value>
        </property>
    </bean>
    <bean id="cronTrigger_1" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref bean="jobDetail_1" />
        </property>
        <!-- Execute once per second -->
        <property name="cronExpression">
            <value>0/1 * * * * ?</value>
        </property>
    </bean>
    
    <!-- Task 2 Configuration -->
    <bean name="job2" class="com.quartz.demo.Job2Demo"/>
    <bean id="jobDetail_2" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject">
            <ref bean="job2" />
        </property>
        <property name="targetMethod">
            <value>sayHello</value>
        </property>
    </bean>
    <bean id="cronTrigger_2" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref bean="jobDetail_2" />
        </property>
        <property name="cronExpression">
            <value>0/1 * * * * ?</value>
        </property>
    </bean>
    
    <!-- Total Configuration -->
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <!-- Add Trigger -->
        <property name="triggers">
            <list>
                <ref bean="cronTrigger_1" />
                <ref bean="cronTrigger_2" />
            </list>
        </property>
    </bean>
</beans>

Java pojo class

package com.quartz.demo;
 
import java.util.Date;
 
public class Job1Demo {
	public void sayHello() {
		System.out.println(new Date() + " -> Hello, I'm Task 1");
	}
}

  

package com.quartz.demo;
 
import java.util.Date;
 
public class Job2Demo {
    public void sayHello() {
        System.out.println(new Date() + " -> Hello, I am Task 2");
    }
}

Attachment: cronExpression expression explanation:

0 0 12 * *?------------------- Triggers at 12:00 p.m. each day
0 1510?* *------------------------------- Triggered at 10:15 a.m. every day
0 1510 * *?---------------- Triggers every day at 10:15 a.m.
0 1510 * *?*---------------------- Triggers every day at 10:15 a.m.
0 1510 * *? 2005---------------- Triggered at 10:15 a.m. every day in 2005
0 * 14 * *?----------------- Triggers every minute between 2:00 p.m. and 2:59 p.m. every day
0/5 14 * *?--------------------- Triggers every 5 minutes between 2:00 and 2:59 p.m. every day
0/5 14,18 * *?-------------------- Triggers every 5 minutes between 2:00 and 2:59 p.m. and 6:00 and 6:59 p.m. every day
0-5 14 * *?--------------------- Triggers every minute between 2:00 p.m. and 2:05 p.m. every day
0 10,44 14? 3 WED----------------------- Triggers every Wednesday in March at 2:00 p.m. and 2:44 p.m.
0 1510? * MON-FRI---------------------------- Triggered every morning from Monday to Friday at 10:15 a.m.
0 15 10 15 *?---------------------- Triggers every 15 days of the month at 10:15 a.m.
0 15 10 L *?---------------------- Triggered at 10:15 on the last day of each month
0 1510? * 6L------------------ Triggers at 10:15 a.m. on the last Friday of each month
0 1510? * 6L 2002-2005---------------------------- Triggered at 10:15 a.m. on the last Friday of each month in 2002, 2003, 2004 and 2005
0 1510? * 6#3-------------------------- Triggers at 10:15 a.m. on the third Friday of each month
0 121/5 *?------------------- Triggered every 5 days from the first day of the month at 12:00 p.m.
0 11 11 11 11?---------------------- Triggers at 11:11 a.m. on each November 11.
 
 

The'*'character is used to specify all values.For example: "*" means "every minute" in the field field field of minutes.(

The'-'character is used to specify a range.For example, "10-12" in the hour domain means "10, 11, 12".
 
The character is used to specify another value.For example, "MON,WED,FRI" means "Monday, Wednesday, Friday" in the week domain.

The'?'character is used only in date and week fields.It is used to specify "ambiguous values".It is useful when you need to specify something in one of these two domains.Look at the examples below and you will see.(


The "L" character specifies the day of the month or week (last day).This is the abbreviation for Last.But in the week and month,'L'means different things, for example,'L' in the sub-paragraph of the month refers to the last day of the month - January 31, February 28, or simply'7'or'SAT' in the week field.If a value is followed by a value in the week field, it means "the last week value of a month", for example, "6L" means the last Friday of a month.

The "W" character can only be used in the month field, which specifies the Sunday closest to the specified date.

The'#'character can only be used in the week field, which specifies which week value is in a month


 

"0 0 12 * * ?"   Trigger every day at 12 noon
"0 15 10 ? * *"   Trigger every day at 10:15 a.m.
"0 15 10 * * ?"   Trigger every day at 10:15 a.m.
"0 15 10 * * ? *"   Trigger every day at 10:15 a.m.
"0 15 10 * * ? 2005"   Triggered at 10:15 a.m. every day in 2005
"0 * 14 * * ?"   Triggered every minute between 2 p.m. and 2:59 p.m. each day
"0 0/5 14 * * ?"   Triggered every 5 minutes between 2 p.m. and 2:55 p.m. each day
"0 0/5 14,18 * * ?"   Triggers every 5 minutes between 2 p.m. and 2:55 p.m. and between 6 p.m. and 6:55 p.m. each day
"0 0-5 14 * * ?"   Triggered every minute between 2 p.m. and 2:05 p.m. each day
"0 10,44 14 ? 3 WED"   Triggered every Wednesday, March at 2:10 and 2:44 p.m.
"0 15 10 ? * MON-FRI"   Triggered at 10:15 a.m. Monday to Friday
"0 15 10 15 * ?"   Triggered at 10:15 a.m. on 15th of each month
"0 15 10 L * ?"   Triggered at 10:15 on the last day of each month
"0 15 10 ? * 6L"   Triggered at 10:15 a.m. on the last Friday of each month
"0 15 10 ? * 6L 2002-2005"   Triggered at 10:15 a.m. on the last Friday of each month, 2002-2005
"0 15 10 ? * 6#3"   Triggered at 10:15 a.m. on the third Friday of each month

Posted by SuNcO on Mon, 08 Jul 2019 09:46:54 -0700