What can be the reasons for a TimerTask to stop running in a Tomcat Servlet

旧城冷巷雨未停 提交于 2019-12-02 11:43:21

TimerTasks die when an uncaught exception is thrown (whether it's running in tomcat or not is unrelated). The easiest way to resolve this is to catch RuntimeException in your run method, and log & continue if that's what you want.

It's also advisable to catch Throwables as well and log it before you rethrow it so that you can see the stacktrace in your logs, like this:

    try{
        doRun();
    }catch (RuntimeException e){
        logger.error("Uncaught Runtime Exception",e);
        return; // Keep working
    }catch (Throwable e){
        logger.error("Unrecoverable error",e);
        throw e;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!