aspose file tools*
The moose likes Servlets and the fly likes testing a session variable and synchronized question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "testing a session variable and synchronized question" Watch "testing a session variable and synchronized question" New topic
Author

testing a session variable and synchronized question

Sam Walker
Ranch Hand

Joined: Nov 06, 2002
Posts: 65
I have some questions about synchronization of session variables. I�m storing the name of a jsp file in the http session. I use that name later to include the jsp file in another jsp page. The First interesting thing I came across when I started doing this was that I couldn�t find a way to test if the session was active and all variables were there without testing for null value for variables. I�m thinking may I missed something when I was researching this, if anyone has any hints please enlighten me. Anyway I decided to set a variable that acts like a flag. It would get a value whenever a session is created and hold it until the session is expired. I then test for the value of the flag in my doPost(). My question is do I need to use synchronized when I test the flag? I think I don�t because synchronize is used only when the value of an instance variable is modified. In my case the flag is not an instance variable and I am not updating it, it�s created when a new session is created.
Thanks in advance for your advice.
Murali Nanchala
Ranch Hand

Joined: Mar 14, 2001
Posts: 74
Check out methods on javax.servlet.http.HttpSession. Especially, the getCreationTime(), getLastAccessedTime() and isNew().
What is wrong with checking for nulls anyway?
Why synchronize? You don't share sessions.
[ June 04, 2003: Message edited by: Murali Nanchala ]

"It is almost always answered in the API" - Murali Nanchala
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: testing a session variable and synchronized question