首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring2.0 Quartz 实施每天定时任务 普通普是执行任务

2012-09-11 
spring2.0 Quartz 执行每天定时任务 普通普是执行任务此类为执行任务计划的类package com.tht.common.job.

spring2.0 Quartz 执行每天定时任务 普通普是执行任务

此类为执行任务计划的类

package com.tht.common.job.spring;import org.quartz.JobExecutionException;import org.springframework.scheduling.quartz.QuartzJobBean;import org.apache.log4j.Logger;/** * Created by IntelliJ IDEA. * User: liuwen * Date: 2010-11-6 * Time: 20:35:02 * To change this template use File | Settings | File Templates. */public class DemoJob {    Logger log=Logger.getLogger(DemoJob.class);    public void execute(){        log.info("执行了定时任务。。。");    }}

?

?

测试类:

package com.tht.common.job.spring;import org.apache.log4j.Logger;import org.quartz.Scheduler;import org.quartz.SchedulerException;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(TimerTaskDemo.class);    public static void main(String[] args){        ApplicationContext context=new ClassPathXmlApplicationContext("beans-config.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());            }        }        Scheduler scheduler =(Scheduler)context.getBean("schedulerFactoryBean");        try {            scheduler.shutdown();        } catch (SchedulerException e) {            log.error(e.getMessage(), e.fillInStackTrace());        }    }}

?配置文件:beans-config.xml

热点排行