zoukankan      html  css  js  c++  java
  • 三)Wiring up jobs using triggers and the SchedulerFactoryBean

    示例地址: 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");
        }
    }
  • 相关阅读:
    Poj(1459),最大流,EK算法
    Poj(3259),SPFA,判负环
    HDU(3790),最短路二级标准
    Poj(2349),最小生成树的变形
    CSUFT2016训练赛
    NYOJ(21),BFS,三个水杯
    Poj(3687),拓扑排序,
    Poj(2367),拓扑排序
    HDU(1856),裸的带权并查集
    HDU(1572),最短路,DFS
  • 原文地址:https://www.cnblogs.com/zno2/p/4891237.html
Copyright © 2011-2022 走看看