Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8526029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:09:10+00:00 2026-06-11T08:09:10+00:00

I have HttpSessionListener registered in application (written with Grails 1.3.6 uses Spring 3.0.5). I

  • 0

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());
    context.publishEvent(e);
}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:09:12+00:00Added an answer on June 11, 2026 at 8:09 am

    In this particular example, could you not just check yourself whether the context is closed before publishing your event?

    public void sessionDestroyed(HttpSessionEvent event) {        
        ApplicationContext context = getContext(event.getSession().getServletContext());
        if(((ConfigurableApplicationContext)context).isActive()) {
            HttpSessionDestroyedEvent e = new HttpSessionDestroyedEvent(event.getSession());
            context.publishEvent(e);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my grails application, I have implemented the interface HttpSessionListener to listen for session
have written this little class, which generates a UUID every time an object of
have 2 questions : A computer with 32-bit address uses 2-level page table (9
Is there a way in Spring to get an object programmatically as if it
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
I have a web application built using jsp/servlets.The web application session is set to
I have a JSF application that, in a managed bean, calls business logic from
I am trying to use a HttpSessionListener to check for a cookie and get
I have the following implementation of HttpSessionlistener public class SessionListener implements HttpSessionAttributeListener, HttpSessionListener {
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.