aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Session persist when server shuts down? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Session persist when server shuts down?" Watch "Session persist when server shuts down?" New topic
Author

Session persist when server shuts down?

Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
A mock exam question states that if the container is shutdown and brought up again, the session still persists.
Is this true?


BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
Kyle Tang
Ranch Hand

Joined: Aug 22, 2002
Posts: 78
If the web-app is distributed, then the Session could be migrated to another web-container. Later when the old web-container re-starts, the Session could be migrated back to it. So the Session is always available.
Kyle


Kyle Tang<br />SCJP 91<br />SCWCD 96<br />SCBCD 95
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
How about if the web-app is not distributed?
Thanks.
Kyle Tang
Ranch Hand

Joined: Aug 22, 2002
Posts: 78
if your web-app is not distributed, then no way to save anything. Session is gone, everything is gone.
Kyle
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
If you kept the session id (through cookies) you can maintain the session. Try this experiment with Tomcat4:
// a.jsp
<%
session.setAttribute("test", "HI");
%>
<%= session.getId() %>
//b.jsp
<%= (String) session.getAttribute("test") %>
Put them in your webapp and access a.jsp. Note and copy the sessionid displayed. Kill the browser and restart Tomcat4.
Access b.jsp and attach jsessionid={whatever sessionid you got} to the URL, e.g
http://localhost:8080/myContext/b.jsp;jsessionid=0B1816DE194C7A3E78F962B16052F79E[/QB]
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
Thanks.
It is interesting. It appears that if I use URL-rewriting for session tracking then all my pages would have sessionid attached and the session would survive in server down.
Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
Yes all of this is interesting..that's why I was totally wrong before and confused when I answered that one person's question about when the browser shuts down. So let me make sure I have this correct...
If the browser is completely shut down all the user lost was his session id tracked in a temporary cookie(or URL) to a true session on the server?
Kyle Tang
Ranch Hand

Joined: Aug 22, 2002
Posts: 78
Thanks guys. I learnt.
My guess is Tomcat keeps track of the on-going sessions, and upon Normal shutdown of Tomcat, it will save the status(Probably serialize the attributes in the sessions, save the session ID, save the time-out values, etc). So next time it starts up, it will read the status, and if the client sends a HTTP request with a cookie header or the jsessionid is contained in URL, Tomcat will verify the timeout, if not timed-out yet, the session will be in use again.
Two things,
1. If you kill the Tomcat process, say on Unix do a "kill -9", I guess Sessions can't get re-activated upon Tomcat restart.
2. This is a nice feature of Tomcat, but not required by Spec, and not guaranteed by web-containers. So, if the exam really asks about this(probably not), guess the best.
Kyle
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session persist when server shuts down?