读书人

Spring2.0 job 普普通通类中定时任务

发布时间: 2012-09-06 10:37:01 作者: rapoo

Spring2.0 job 普通类中定时任务

package com.tht.common.job.spring.general;import com.tht.common.job.spring.DemoTask;import org.apache.log4j.Logger;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Timer;/** * Created by IntelliJ IDEA. * User: liuwen * Date: 2010-11-6 * Time: 19:43:29 * To change this template use File | Settings | File Templates. * 启动类,并控制何时关闭时钟任务 */public class TimerTaskDemo {     static Logger log=Logger.getLogger(DemoTask.class);    public static void main(String[] args){        ApplicationContext context=new ClassPathXmlApplicationContext("beans-config-general.xml");        log.info("启动任务。。。。。。");        log.info("请输入exit,关闭任务");        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));        while(true){            try {                if(reader!=null && "exit".equals(reader.readLine())){                    break;                }            } catch (IOException e) {                log.error(e.getMessage(), e.fillInStackTrace());            }        }        Timer timer =(Timer)context.getBean("timerFactoryBean");        timer.cancel();    }}
?

读书人网 >软件架构设计

热点推荐