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);
    }
    }
     
     
  • 相关阅读:
    MySQL7:性能优化
    MySQL6:视图
    MySQL5:触发器
    MySQL4:索引
    MySQL3:存储过程和函数
    MySQL1:MySQL函数汇总
    MySQL2:四种MySQL存储引擎
    Spring7:基于注解的Spring MVC(下篇)
    Spring6:基于注解的Spring MVC(上篇)
    Linux查看端口号
  • 原文地址:https://www.cnblogs.com/libo199374/p/9714395.html
Copyright © 2011-2022 走看看