是不是因为程序里的异常没有捕获????

解决方案 »

  1.   

    如果用的是Timer,那么出异常了极可能挂掉:http://www.ticmy.com/?p=82
      

  2.   

    package service;import java.util.*;import org.apache.log4j.Logger;
    public class AutoMatic {

      static Logger logger = Logger.getLogger ( AutoMatic.class.getName () ) ;
        //程序启动一分钟后开始统计
    static long timerDelay = 1000 * 60 * 1L;
    //间隔时间,每2小时插一次
    static long timerPeriod = 1000 * 60 * 60 *2L;

    // {
    // try{
    // new Timer().schedule(new AutoMaticTimerTask(), timerDelay, timerPeriod);//timerDelay从现在开始延迟执行的时间               timerPeriod 延迟参数的时间单位 
    // System.out.println("服务已启动.服务启动一分钟后开始进行读取数据.");
    // }catch (Exception e) {
    // System.err.println("服务启动失败.");
    // logger.error("#ERROR# :服务启动失败!", e);
    // }
    // }
    class AutoMaticTimerTask extends TimerTask{
    public void run(){

    System.out.println("开始读取数据!");
    try {
    new ReportMinperiodService().selectBeforeTime();
    ReportMinperiodService.ANALYSE_LOCKED=false;
    System.out.println("ReportMinperiodService----->插值结束!!");
    new ReportDayService().selectBeforeTime();
    ReportDayService.ANALYSE_LOCKED=false;
    System.out.println("ReportDayService----->插值结束!!");
    new ReportMonthService().selectBeforeTime();
    ReportMonthService.ANALYSE_LOCKED=false;
    System.out.println("ReportMonthService----->插值结束!!");
    new WrReportMinperiodService().selectBeforeTime();
    WrReportMinperiodService.ANALYSE_LOCKED=false;
    System.out.println("WrReportMinperiodService------>插值结束");
    new WrReportDayService().selectBeforeTime();
    WrReportDayService.ANALYSE_LOCKED=false;
    System.out.println("WrReportDayService------>插值结束");
    new WrReportMonthService().selectBeforeTime();
    WrReportMonthService.ANALYSE_LOCKED=false;
    System.out.println("WrReportMonthService------>插值结束");
    new JzqEmsBaseService().selectBeforeTime();
    JzqEmsBaseService.ANALYSE_LOCKED=false;
    System.out.println("JzqEmsBaseService------>插值结束!!");
    new JzqMidOutputService().selectBeforeTime();
    JzqMidOutputService.ANALYSE_LOCKED=false;
    System.out.println("JzqMidOutputService------>插值结束!!");


    } catch (Exception e) {
    e.printStackTrace();
      logger.error("#ERROR# :插入错误!", e);
    }

    }

    }

    public static void main(String[] args) {
    try{

    new Timer().schedule(new AutoMatic().new AutoMaticTimerTask(), timerDelay, timerPeriod);//timerDelay从现在开始延迟执行的时间               timerPeriod 延迟参数的时间单位 
    System.out.println("服务已启动.一分钟后开始进行读取数据.");
    }catch (Exception e) {
    System.err.println("服务启动失败.");
    logger.error("#ERROR# :服务启动失败!", e);
    }
    }
    }
      

  3.   

    如果已经catch了,那么可以查查系统时间有没有被改过,Timer对系统时间更改也很敏感
      

  4.   

    重启下tomcat,看定时器有没有执行,另外看下报错日志。可能是因为中途tomcat挂掉的原因
      

  5.   


    没用tomcat  直接在服务器上执行的!!
      

  6.   

    楼主说的是定时器停了还是服务器停了?
    如果是服务器停了的话,排除其他问题的可能性的话,就是定时器代码中有消耗资源的代码导致内存不足挂掉了!
    如果是定时器停了的话,就要靠看是一开始就不能正常的运行定时器代码,
    还是运行了一段时间过后在某次执行的时候出错导致服务崩溃。
    建议debug调试,肯定能发现问题
      

  7.   

    我这主要是从webService上每隔两小时取一次数据,但是每天夜里12点也就是00点就停止了  重新启动正常运行   服务器也没停  请问是怎么回事????
      

  8.   


    写了个死循环   让他执行一段时间    sleep一下     就没有这种问题了