• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session's invalidation behaviour

 
Saurabh Kumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Here is a question:

In which of the following situations will a session be definitely invalidated?

Select 3 correct options.
A.The container is shutdown and brought up again
B.No request comes from the client for more than "session timeout" period.
C.A servlet explicitly calls invalidate() on a session object.
D.A servlet explicitly calls invalidate() on a session object.
ANS : B,C,D

My Question is: Is there a possibility that a session might not be invalidated even the container is restarted? this relates to option A.

Thanks and regards,
Saurabh
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saurabh,

Yes it is possible that a session is not invalicdated if the container is shutdown and then restarted. I have done this on Tomcat, infact if memory serves correctly its the standard behaviour on tomcat.

For example create a servlet/jsp that saves something into the HttpSession. then another that displays what was saved in the HttpSession

Point your browser at the first one, wait till the page comes up, then shut the server down, and restart it. Then point your browser at the second page.

I have done this with tomcat and had what was save into the session displayed on the page. The simple reason is that Sessions are serialised to the file system and then reloaded from the filesystem on a new request. Tomcat does not clear its cache of session data when restarted so its still there.

HTH
Matt
 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is option C different from Option D ??
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option C and D are identical
I was assuming (maybe incorrectly) that one was just a typo.

Matt
 
Tanveer Ahmad
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matt,
Thanks for your reply. To add to the concept, this supports the behaviour of a web application in distributed environment. Now if a server goes down the application still has to run and this can't happen if the sessions objects (living in that server) get invalidated when server goes down.

Saurav,
Please let me know the option D. I want to know what is the third way of invalidating the session.

Cheers
Tanveer
 
Saurabh Kumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mat, Tanveer.

I found this question hereJavaBeat

I copied the question as is, I ignored this considering it "typo".

If you find something relevant to Tanveer's question, please let me also know.

Thanks and regards,
Saurabh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic