• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Session persist when server shuts down?

 
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A mock exam question states that if the container is shutdown and brought up again, the session still persists.
Is this true?
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about if the web-app is not distributed?
Thanks.
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if your web-app is not distributed, then no way to save anything. Session is gone, everything is gone.
Kyle
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic