码迷,mamicode.com
首页 > 其他好文 > 详细

三)Wiring up jobs using triggers and the SchedulerFactoryBean

时间:2016-08-06 08:19:37      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

示例地址: https://github.com/witaste/quartz.git

│  pom.xml
│
└─src
    └─main
        ├─java
        │  └─cn
        │      └─zno
        │          └─job
        │                  Breathe.java
        │                  Main.java
        │
        └─resources
                Beans-Quartz.xml

 

两种触发器:简单的触发器和cron表达式触发器

 

<?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.xsd">


    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
<!--                 <ref bean="cronTrigger" /> -->
                <ref bean="simpleTrigger" />
            </list>
        </property>
    </bean>

    <bean id="simpleTrigger"
        class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
        <property name="jobDetail" ref="jobDetail" />
        <property name="startDelay" value="10000" />
        <property name="repeatInterval" value="1000" />
    </bean>

<!--     <bean id="cronTrigger" -->
<!--         class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> -->
<!--         <property name="jobDetail" ref="jobDetail" /> -->
<!--         <property name="cronExpression" value="* * * ? * *" /> -->
<!--     </bean> -->


    <bean id="jobDetail"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="breath"></property>
        <property name="targetMethod" value="show"></property>
    </bean>

    <bean id="breath" class="cn.zno.job.Breathe" />
</beans>

 

package cn.zno.job;

public class Breathe {

    public void show() {
        System.out.println(11);
    }

}

 

package cn.zno.job;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class Main {
    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("Beans-Quartz.xml");
    }
}

 

三)Wiring up jobs using triggers and the SchedulerFactoryBean

标签:

原文地址:http://www.cnblogs.com/zno2/p/4891237.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!