Quartz Records

<!-- 注册自定义作业类 -->
    <bean id="myJob" class="com.itheima.jobs.MailJob">
        <property name="username" value="[email protected]"/>
        <property name="password" value="147963qP"/>
        <property name="smtpServer" value="smtp.126.com"/>
    </bean>

    <!-- 配置JobDetail -->
    <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 注入目标对象 -->
        <property name="targetObject" ref="myJob"/>
        <!-- 注入目标方法 -->
        <property name="targetMethod" value="execute"/>
    </bean>

    <!-- 配置触发器 -->
    <bean id="myTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <!-- 注入任务详情对象 -->
        <property name="jobDetail" ref="jobDetail"/>
        <!-- 注入cron表达式,通过这个表达式指定触发的时间点 -->
        <property name="cronExpression">
            <value>0/5 * * * * ?</value>
        </property>
    </bean>

    <!-- 配置调度工厂 -->
    <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <!-- 注入触发器 -->
        <property name="triggers">
            <list>
                <ref bean="myTrigger"/>
            </list>
        </property>
    </bean>

In actual use, the generator
cron expression is used on the Internet. The 6-7 domain years are optional
(1) : it means any value that matches the domain. If used in the Minutes field , it means that the event will be triggered every minute.

(2)?: It can only be used in the fields of DayofMonth and DayofWeek. It also matches arbitrary values ​​of the domain, but doesn't actually. Because DayofMonth and DayofWeek will affect each other. For example, if you want to trigger scheduling on the 20th of each month, no matter what day of the week the 20th is, you can only use the following writing method: 13 13 15 20 * ?, where the last digit can only be used? , and cannot be used , if it is used to indicate that it will fire regardless of the day of the week, which is not the case.

  (3)-: Indicates the range. For example, use 5-20 in the Minutes field, which means that it is triggered every minute from 5 minutes to 20 minutes.

  (4)/: Indicates that the trigger starts at the start time, and then triggers every fixed time. For example, using 5/20 in the Minutes field means that it is triggered once every 5 minutes, and once every 25, 45, etc.

  (5),: Indicates that enumeration values ​​are listed. For example: use 5,20 in the Minutes field, it means to fire every minute at 5 and 20 minutes.

  (6) L: Indicates the last, which can only appear in the DayofWeek and DayofMonth fields. If you use 5L in the DayofWeek field, it means triggering on the last Thursday.

  (7) W: Indicates a valid working day (Monday to Friday), which can only appear in the DayofMonth field, and the system will trigger the event on the valid working day closest to the specified date. For example: use 5W on DayofMonth, if the 5th is Saturday, it will trigger on the nearest weekday: Friday, which is the 4th. If the 5th is Sunday, it will trigger on the 6th (Monday); if the 5th is one of Monday to Friday, it will trigger on the 5th. Another point, W's most recent searches don't span months.

  (8) LW: These two characters can be used together to indicate the last working day of a month, that is, the last Friday.

  (9) #: Used to determine the day of the week in each month, which can only appear in the DayofMonth field. For example, in 4#2, it means the second Wednesday of a month.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324603321&siteId=291194637