Announcement Announcement Module
No announcement yet.
publishEvent on closed context Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • publishEvent on closed context

    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.

    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());
    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.

    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.

  • #2
    I don't understand why are to trying to do a context.publishEvent(HttpSessionEvent) again because your callback interface is receiving this callback already as a result of the application context publish this event to all the listeners registered with it. Can you remove this line and reconfirm that you're problem still occurs?