Spring项目 使用quartz定时执行任务
        【摘要】 
                    1.导入jar包 
我使用的jar包版本是quartz-all-1.8.5。jar包下载地址参考:https://www.cr173.com/soft/65793.html 
2.配置application-context文件 
<!--执行任务类---><bean id="aaa" class="com.xxx.ti...
    
    
    
    1.导入jar包
我使用的jar包版本是quartz-all-1.8.5。jar包下载地址参考:https://www.cr173.com/soft/65793.html
2.配置application-context文件
  
   - 
    
     
    
    
     
      <!--执行任务类--->
     
    
- 
    
     
    
    
     
      <bean id="aaa" class="com.xxx.timing.test.timing"></bean> 
     
    
- 
    
     
    
    
     
      <!--配置定时任务-->
     
    
- 
    
     
    
    
     
      <bean id ="compareJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
     
    
- 
    
     
    
    
     	<property name ="targetObject" ref ="aaa"/> 
     
    
- 
    
     
    
    
     	     <property name ="targetMethod" value ="run"/> 
     
    
- 
    
     
    
    
     	<property name ="concurrent" value ="false"/> 
     
    
- 
    
     
    
    
     
      </bean>
     
    
- 
    
     
    
    
     
      <bean id ="compareTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> 
     
    
- 
    
     
    
    
     	<property name ="jobDetail" ref ="compareJob" /> 
     
    
- 
    
     
    
    
     	     <property name ="cronExpression" >
     
    
- 
    
     
    
    
             <!--没5秒执行一次-->              
     
    
- 
    
     
    
    
     	     <value>*/5 * * * * ?</value> 
     
    
- 
    
     
    
    
     
      	</property > 
     
    
- 
    
     
    
    
     
      </bean >
     
    
- 
    
     
    
    
          
     
    
- 
    
     
    
    
     
      <bean id ="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" > 
     
    
- 
    
     
    
    
     	<property name ="triggers" > 
     
    
- 
    
     
    
    
     	     <list >                     
     
    
- 
    
     
    
    
     	        <ref local ="compareTrigger"/> 
     
    
- 
    
     
    
    
     
      	     </list > 
     
    
- 
    
     
    
    
     
      	</property > 
     
    
- 
    
     
    
    
     
      </bean >
     
    
 3.执行任务类代码
  
   - 
    
     
    
    
     
      package com.xxx.timing.test;
     
    
- 
    
     
    
    
     
      import org.quartz.JobExecutionException;
     
    
- 
    
     
    
    
     
      public class timing{
     
    
- 
    
     
    
    
         
     
    
- 
    
     
    
    
         public void run()throws JobExecutionException{
     
    
- 
    
     
    
    
             long ms = System.currentTimeMillis();  
     
    
- 
    
     
    
    
     
              System.out.println("\t\t" + new Date(ms));  
     
    
- 
    
     
    
    
     
          }
     
    
- 
    
     
    
    
     
      }
     
    
 
文章来源: chensj.blog.csdn.net,作者:_陈哈哈,版权归原作者所有,如需转载,请联系作者。
原文链接:chensj.blog.csdn.net/article/details/92377905
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        
        
        - 点赞
- 收藏
- 关注作者
 
             
           
评论(0)