Srping定时器









  
   
  

  
    5000
   
  

  
    5000
   
  





  
   
    
   

  






  
    cn.xg.spring.QuartzClock
  







  
   
  

  
    0 52 22 * * ?
    
  

  



  
   
    
   

  


clock.java

package cn.xg.spring;

import java.util.TimerTask;

public class Clock extends TimerTask{

@Override
public void run() {
  
   System.out.println("clock..!clock....!.......");
  
}

}

QuartzClock .java

package cn.xg.spring;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

public class QuartzClock extends QuartzJobBean {

@Override
protected void executeInternal(JobExecutionContext arg0)
    throws JobExecutionException {
  
   System.out.println("QuartzClock..!QuartzClock....!.......");
}

}

 

SpringTest .java
package cn.xg.spring;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringTest {

/**
* @param args
*/
public static Logger log = Logger.getLogger(SpringTest.class);

public static void main(String[] args) {
  

  
   //第一种写法(加载配置文件)
   ApplicationContext ctx = new
   ClassPathXmlApplicationContext("applicationContext.xml");
  
   //第二种写法
   //ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/applicationContext.xml");
   //ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
  
   //加载多个配置文件
   // ApplicationContext ctx = new ClassPathXmlApplicationContext(
        //new String[]{"applicationContext.xml","applicationContext2.xml"} );
  

}

}

 

所需要的jar包:

spring.jar;quartz-all-1.6.0.jar;commons-collections.jar;可能还要commons-*.jar

出处地址:http://hi.baidu.com/jakey766/blog/item/612f08089759d7a72fddd45e.html

你可能感兴趣的:(WEB开发)