This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I need to track when a users session is about to timeout. After searching through the topics in "The Ranch" and doing a little reading on my own it appears that my best bet is to implement HttpSessionActivationListener. I can then perform my cleanup in the sessionWillPassivate() method. My understanding is that this will serve a double purpose by being called not only when the session is about to timeout but also on a call to session.invalidate(). I know that when you use an HttpSessionListener you have to register it with the web.xml. Is this true of the ActivationListener as well? If not, how do the servlets recognize where to send the event?
U know HttpSession migrate from one jvm to another,so the spec designers design an listener to find whether the attributes in the HttpSession were also about to move.So there came a HttpSessionActivationListener.
If all ur attributes r straight forward serializable then u don't need to care about this listener.
So ur question is about ur using HttpSessionActivation listener,and how do we register it.right.My opinion is for any listener we need to register the class in web.xml.I hope this might me true.
SCJP:70%<br />SCWCD:86%<br />SCBCD:90%<br />scdjws:98%<br />OCA<br />Nothing is impossible.Try and try until you achieve it.<br /> <br />Interstesigning and developing web Components
Firstly, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.
I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.
Alright, I'm implementing HttpSessionListener. I've declared my class in web.xml and set the session to timeout in 5 minutes for testing purposes. When the session times out I get the following exception thrown to the console. The web page seems unaffected.
The process that I followed was to log in to the application so that my session is loaded with the appropriate objects and then sit on that web page until session timeout is reached. Also, it doesn't appear that the code to finalize session objects I placed in sessionDestroyed() is reached. It enters the method and then...
Can you tell us what container and version you are using? Also, if you know what version of the Servlet Spec your container supports, that would be helpful.
I know there was a change in the J2EE API (between 1.3 and 1.4) in the way (when) the sessionDestroyed method is called. In a nutshell sessionDestroyed used to be called after the session was destroyed and now get's called before.
This thread has links to the two APIs and discusses their differences.
I'm using the version 1.4.2 Java APIs running against a SunOne Web Server (6.1) and a BEA WebLogic Application Server (8.1).
Basically the problem is that some of our users can run reports in the background. What I need to do is check to make sure that the reports stop if the session times out. They run in a seperate thread that's referenced from an object stored in the session. That's the finalization code I spoke of previously which isn't being reached. Any help would be tremendously appreciated. In the meantime I'll look at those links. Thanks.