Java定时器quartz和spring集成

public class QuartzJob 
{ 
     public void work() 
     { 
             System.out.println(Spring Quartz的任务调度1被调用!"); 
             //定时调用的业务逻辑 
     } 
} 

public class QuartzJob2
{ 
     public void work() 
     { 
             System.out.println(Spring Quartz的任务调度2被调用!"); 
             //定时调用的业务逻辑 
     } 
}
复制代码

Spring的配置文件

复制代码




    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

        
        class="com.writchie.quartz.QuartzJob"> 
         class="com.writchie.quartz.QuartzJobTwo">
       
          

          
         class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> 
              
              
                  
              
              
              
                 work 
              
          

         class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> 
              
              
                  
              
              
              
                 work 
              
          
          
        

          
         class="org.springframework.scheduling.quartz.CronTriggerBean"> 
              
                  
              
              
              
                 10,15,20,25,30,35,40,45,50,55 * * * * ? 
              
          
         
         class="org.springframework.scheduling.quartz.CronTriggerBean"> 
              
                  
              
              
              
                 0 15 13 ? * SUN-SAT 
              
          
          
          

   
         class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
              
                  
                      
                      
                    

                  
              
          
        
 

测试程序

import org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
public class QuartzService { 
public static void main(String[] args) { 
   System.out.println("测试任务调度开始..."); 
   ApplicationContext context = new ClassPathXmlApplicationContext( 
     "applicationContext.xml"); 
   // 如果配置文件中将startQuertz bean的lazy-init设置为false 则不用实例化 
   // context.getBean("startQuertz"); 
   System.out.print("测试任务调度结束!\n"); 

你可能感兴趣的:(java)