乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      spring自帶的定時(shí)任務(wù)功能,基于注解和xml配置

       青_春 2016-07-11

      1、spring的配置文件

      [html] view plain copy
       在CODE上查看代碼片派生到我的代碼片
      1. <beans xmlns="http://www./schema/beans"  
      2.     xmlns:xsi="http://www./2001/XMLSchema-instance"   
      3.     xmlns:p="http://www./schema/p"  
      4.     xmlns:task="http://www./schema/task"  
      5.     xmlns:context="http://www./schema/context"  
      6.     xmlns:aop="http://www./schema/aop"   
      7.     xsi:schemaLocation="http://www./schema/beans   
      8.     http://www./schema/beans/spring-beans-3.0.xsd  
      9.     http://www./schema/tx http://www./schema/tx/spring-tx-3.0.xsd    
      10.     http://www./schema/jee http://www./schema/jee/spring-jee-3.0.xsd    
      11.     http://www./schema/context http://www./schema/context/spring-context-3.0.xsd    
      12.     http://www./schema/aop http://www./schema/aop/spring-aop-3.0.xsd    
      13.     http://www./schema/task http://www./schema/task/spring-task-3.0.xsd">  
      14.   
      15.     <task:annotation-driven /> <!-- 定時(shí)器開(kāi)關(guān)-->  
      16.   
      17.     <bean id="myTaskXml" class="com.spring.task.MyTaskXml"></bean>  
      18.   
      19.     <task:scheduled-tasks>  
      20.         <!--  
      21.             這里表示的是每隔五秒執(zhí)行一次  
      22.         -->  
      23.         <task:scheduled ref="myTaskXml" method="show" cron="*/5 * * * * ?" />  
      24.         <task:scheduled ref="myTaskXml" method="print" cron="*/10 * * * * ?"/>  
      25.     </task:scheduled-tasks>  
      26.       
      27.     <!-- 自動(dòng)掃描的包名 -->    
      28.     <context:component-scan base-package="com.spring.task" />  
      29.       
      30. </beans>  

      2、基于xml的定時(shí)器任務(wù)

      [java] view plain copy
       在CODE上查看代碼片派生到我的代碼片
      1. package com.spring.task;  
      2.   
      3. /** 
      4.  * 基于xml的定時(shí)器 
      5.  * @author hj 
      6.  */  
      7. public class MyTaskXml {  
      8.       
      9.       
      10.     public void show(){  
      11.         System.out.println("XMl:is show run");  
      12.     }  
      13.       
      14.     public void print(){  
      15.         System.out.println("XMl:print run");  
      16.     }  
      17. }  

      3、基于注解的定時(shí)器任務(wù)

      [java] view plain copy
       在CODE上查看代碼片派生到我的代碼片
      1. package com.spring.task;  
      2.   
      3. import org.springframework.scheduling.annotation.Scheduled;  
      4. import org.springframework.stereotype.Component;  
      5.   
      6. /** 
      7.  * 基于注解的定時(shí)器 
      8.  * @author hj 
      9.  */  
      10. @Component  
      11. public class MyTaskAnnotation {  
      12.       
      13.     /**  
      14.      * 定時(shí)計(jì)算。每天凌晨 01:00 執(zhí)行一次  
      15.      */    
      16.     @Scheduled(cron = "0 0 1 * * *")   
      17.     public void show(){  
      18.         System.out.println("Annotation:is show run");  
      19.     }  
      20.       
      21.     /**  
      22.      * 心跳更新。啟動(dòng)時(shí)執(zhí)行一次,之后每隔2秒執(zhí)行一次  
      23.      */    
      24.     @Scheduled(fixedRate = 1000*2)   
      25.     public void print(){  
      26.         System.out.println("Annotation:print run");  
      27.     }  
      28. }  

      4、測(cè)試

      [java] view plain copy
       在CODE上查看代碼片派生到我的代碼片
      1. package com.spring.test;  
      2.   
      3. import org.springframework.context.ApplicationContext;  
      4. import org.springframework.context.support.ClassPathXmlApplicationContext;  
      5.   
      6.   
      7. public class Main {  
      8.     public static void main(String[] args) {  
      9.         ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-mvc.xml");  
      10.     }  
      11. }  
      運(yùn)行結(jié)果:
      Annotation:print run
      Annotation:print run
      Annotation:print run
      XMl:print run
      XMl:is show run
      Annotation:print run
      Annotation:print run


        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多