首页 > 其他 > 详细

三)Wiring up jobs using triggers and the SchedulerFactoryBean

时间:2016-08-06 08:18:05      阅读:109      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!