开发者

Spring Timers on JBoss don't stop when undeployed

开发者 https://www.devze.com 2022-12-19 18:20 出处:网络
I\'m using the spring Quartz SchedulerFactoryBean to run a task (SimpleTriggerBean) every 10 seconds. It works great, except when I undeploy the app, the timer carries on running. The only way to stop

I'm using the spring Quartz SchedulerFactoryBean to run a task (SimpleTriggerBean) every 10 seconds. It works great, except when I undeploy the app, the timer carries on running. The only way to stop it is开发者_StackOverflow社区 to restart the server! Is there some JBoss or Spring configuration which will stop the timer when the app is undeployed?


I had the exact same issue with the Spring Scheduler and destroying the context in a listener did the trick. Example:

public class InitListener implements javax.servlet.ServletContextListener {

    protected static final Logger logger = LoggerFactory.getLogger(InitListener.class);
    protected static final ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext(
        "applicationContext.xml");;

    public void contextInitialized(ServletContextEvent arg0) {
        logger.info("Servlet Context is initialized....");
    }

    public void contextDestroyed(ServletContextEvent arg0) {
        springContext.destroy();
        logger.info("Servlet Context is destroyed....");
    }
}


Found the problem - I was manually initialising the Spring Context without destroying it with the servlet. Added a listener, now it's all sorted.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号