开发者

Spring Timers on JBoss don't stop when undeployed

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜