zoukankan      html  css  js  c++  java
  • spring配置简单的job

    第一步引包

    <dependency>
    <groupId>org.quartz-scheduler</groupId>
    <artifactId>quartz</artifactId>
    <version>1.8.6</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>2.5.4</version>
    </dependency>

    第二步在spring.xml配置文件中加入
    <!--配置需要启动的job 可以多个-->
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
    scope="singleton">
    <property name="triggers">
    <list>
    <!-- <ref bean="newsRbLogDetailCallTrgger"></ref>-->
    <ref bean="newsTestDetailCallTrgger"></ref>
    </list>
    </property>
    </bean>

    <!--简单的job-->
    <bean id="testJob" class="cn.net.withub.monitor.job.testJob" scope="singleton"/><!--包名以及类名-->
    <!--测试job 开始-->
    <bean id="newsRbLogDetail"
    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"
    scope="singleton">
    <property name="targetObject">
    <ref bean="testJob" /><!--bean的id-->
    </property>
    <property name="targetMethod">
    <value>test</value>
    </property>
    <property name="concurrent" value="false"/>
    </bean>
    <bean id="newsRbLogDetailCallTrgger"
    class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <property name="jobDetail">
    <ref bean="newsRbLogDetail" />
    </property>
    <property name="startDelay">
    <value>10000</value>
    </property>
    <property name="repeatInterval">
    <value>1000</value> <!--多少毫秒执行任务-->
    </property>
    </bean>
    <!--测试job 结束-->

    第三部写类与方法
    public class testJob {
    public void test(){
    System.out.println("job开始启动");
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    String sj = sdf.format(date);
    System.out.println(sj);
    }

    public void testRedisjob(){
    System.out.println("job开始启动");
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String sj = sdf.format(date);
    System.out.println(sj);
    }
    }
     
     
  • 相关阅读:
    C语言网 蓝桥杯 1117K-进制数
    C语言网蓝桥杯1116 IP判断
    LeetCode 面试题14- II. 剪绳子 II
    LeetCode 面试题06. 从尾到头打印链表
    LeetCode 面试题05. 替换空格
    LeetCode 面试题04. 二维数组中的查找
    LeetCode 面试题03. 数组中重复的数字
    LeetCode 3. 无重复字符的最长子串
    LeetCode 202. 快乐数
    LeetCode 154. 寻找旋转排序数组中的最小值 II
  • 原文地址:https://www.cnblogs.com/libo199374/p/9714395.html
Copyright © 2011-2022 走看看