zoukankan      html  css  js  c++  java
  • quartz不实现job接口的demo

    1.新建一个类,类名为TestJob2,并定义一个方法为doSomething
    public class TestJob2 {
    public static void doSomething(){
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    System.out.println("现在时间是:"+sdf.format(new Date()));
       }
    }


    2.新建spring_quartz.xml文件,配置如下
    <?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 id="testQuartz" class="cn.net.withub.controller.TestJob2"> </bean>
    <!-- 将需要执行的定时任务注入JOB中。 --> 
    <bean id="testJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
      <property name="targetObject" ref="testQuartz"></property>
      <!-- 任务类中需要执行的方法 -->
      <property name="targetMethod" value="doSomething"></property>
       <!-- 上一次未执行完成的,要等待有再执行。 -->
      <property name="concurrent" value="false"></property>
    </bean>
    
    
    <!-- 基本的定时器,会绑定具体的任务。 -->
    <bean id="testTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean
       <property name="jobDetail" ref="testJob"></property>
    <property name="startDelay" value="3000"></property>
    <!--间隔1秒重复执行-->
    <property name="repeatInterval" value="1000"></property>
    </bean>
    
    
    <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="triggers">
    <list>
    <ref bean="testTrigger"></ref>
    </list>
    </property>
    </bean>
    </beans>


    备注:    引入的quartz的包版本为2.2.0,否则spring集成quartz时,会报java.lang.ClassNotFoundException:org.quartz.impl.JobDetailImpl异常

     

    
    
    
    
    
    
    
    
    
    
    
    
  • 相关阅读:
    Auto X2021 K Increasing Sequence
    拉普拉斯平滑处理 Laplace Smoothing
    博学之
    Python-生成音乐-pyshnth
    Python-Kivy ImportError: DLL load failed: 找不到指定的模块
    Python-Word模板填充-docxtpl
    Python-文字转语音-pyttsx3
    Virtual Box中Ubuntu使用"桥接网卡"不能联网而使用"网络地址转换(NAT)"却可以上网
    STM32的HAL库中的DMA_FLAG_TCIF3_7等几个宏定义的含义
    Linux下编写互相通信的驱动模块并将其加入到内核中
  • 原文地址:https://www.cnblogs.com/libo199374/p/7999919.html
Copyright © 2011-2022 走看看