I have HttpSessionListener registered in application (written with Grails 1.3.6 uses Spring 3.0.5). I catch sessionDestroyed event, get Spring's application context and publish event to it.
This code works fine in most cases. But not all. In case when my application running in production under Tomcat 6 and application server shutdowning, the sessionDestroyed method receives a HttpSessionDestroyedEvent event after spring closes context, destroys all beans and set context's closed property to true. But context still present and it's publish method gets applicationEventMulticaster and tell him to multicast this event. Then multicaster takes its list of registered listeners, do getBean (and at this moment BeanFactory creates this beans) and call them.Code:ApplicationContext getContext(ServletContext servletContext) { return WebApplicationContextUtils.getWebApplicationContext(servletContext); } public void sessionDestroyed(HttpSessionEvent event) { HttpSessionDestroyedEvent e = new HttpSessionDestroyedEvent(event.getSession()); ApplicationContext context = getContext(event.getSession().getServletContext()); context.publishEvent(e); }
It seems that the multicaster shouldn't process call to event listeners in case when context already closed. This behavior made my application do some works that shouldn't be done at the shutdown step.
How can I prevent calls to listeners after context closed? Event publisher implemented in application context does not check that current context is not closed.


Reply With Quote
