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 8450649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:01:34+00:00 2026-06-10T11:01:34+00:00

Why is sessionDestroyed() called only on invalidate or timeout, but not called when the

  • 0

Why is sessionDestroyed() called only on invalidate or timeout, but not called when the server is terminating? How I can make some operations on each session when server is terminating?

  • 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-10T11:01:36+00:00Added an answer on June 10, 2026 at 11:01 am

    Regarding your first question:

    Why sessionDestroyed() called only on invalidate or timeout, but not calling when server is terminating?

    Here is an explanation of why sessionDestroyed() is not getting invoked when shutting down in Tomcat (at least as of Tomcat 6.0.33), from a post on Tomcat: http://comments.gmane.org/gmane.comp.jakarta.tomcat.user/215644

    When I request my web application I receive sessionCreated, when I
    invalidate the session from the code I receive sessionDestroyed.
    Unfortunately when I stop the web application I do not receive
    sessionDestroyed.

    I checked the code where StandardContext is stopped. I can see that
    StandardManager.stop is called which is ok
    But when StandardManager.doUnload() is invoked, in its implementation *
    session.expire(false)* is called where the “false” is actually the flag that
    indicates whether to notify the listeners or not. As it is invoked with
    “false” – the listeners are not invoked.

    This is not my post, and I am attributing credit to Violeta, the author of the post.

    The post provides a way to patch StandardManager.java.

    If you did not want to modify that class (I personally avoid modifying classes that belong to the Application Server whenever possible), there are other approaches you could take.

    Regarding your second question:

    how I can make some operations on each session when server is terminating?

    Why do you want to do operations on each session when the server is terminating? The Servlet specification provides methods for executing code when the server is being shutdown. However, they do not provide a means by which you can perform operations on each active Session (probably by design).

    As this earlier answer mentions, How to access HTTP sessions in Java, Session management should be handled by the Servlet Container, and you may reconsider your current approach to your application.

    For general handling cleanup when the server is being shutdown, you have ServletContextListener.contextDestroyed and Servlet.destroy

    The ServletContextListener interface provides a contextDestroyed lifecycle method

    The Servlet interface provides a destroy method, which is used to release any resources or handle any cleanup when the server is being shutdown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I set session timeout to be 5 minutes in web.xml. And once session expired
How might a person simulate firing the HttpSessionListener.sessionDestroyed object in a session listener? Is
I have an implementation of javax.servlet.http.HttpSessionListener that is supposed to detect user session invalidation/timeout
My webapp has users who login. There is a timeout. Before the session expires,
I need to get a proxied session-scoped bean on the HttpSessionListener.sessionDestroyed() . The objective
How to get any http session by id or all currently active http sessions
I have a web application built using jsp/servlets.The web application session is set to
AFAIK, the httpsessionlisterner implementation listener class is get instantiated when the first session is
I'm trying to tracking valid user Ids in my Java servlet, can I implement
i try to save user session in a hashmap on every cluster. and when

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.