This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes Thread Safety in Action Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Thread Safety in Action Servlets" Watch "Thread Safety in Action Servlets" New topic
Author

Thread Safety in Action Servlets

Jason Stull
Ranch Hand

Joined: Feb 02, 2004
Posts: 47
Hello Struts People,
Any specific pointers on how to make access to the HTTPSession, specifically properties in the session, thread-safe? Should synchronization be used whenever accessing session properties? Is it enough to limit access to session variables just from within the Action Servlet's perform method?
-j


"I believe in coyotes and time as an abstract Explain the change the difference between What you want and what you need there's the key"
Srikanth Shenoy
author
Ranch Hand

Joined: Jan 24, 2004
Posts: 184
HTTP Session variables are your own. They just belong to you no one else.
The question of thread safety doesnt arise


Srikanth Shenoy
Author of Struts Survival Guide : Basics to Best Practices
Jason Stull
Ranch Hand

Joined: Feb 02, 2004
Posts: 47
Thanks Srikanth for your reply. I've heard good things about your Struts book. I guess I'm refering to the Struts API docs for the Action class:
Action
Where it states, "Access to other resources (JavaBeans, session variables, etc.) MUST be synchronized if those resources require protection. (Generally, however, resource classes should be designed to provide their own protection where necessary."
Does this just refer to resources used by more than one session, Singletons, etc?
Srikanth Shenoy
author
Ranch Hand

Joined: Jan 24, 2004
Posts: 184
Hi Jason,
I had never looked at it before. But it definitely sounds vague.
I am not exactly sure what they were trying to convey.
I would take a guess: They are probably referring to shared resources, and, as you said, singleton loosely belongs to shared resource category.
 
jQuery in Action, 2nd edition
 
subject: Thread Safety in Action Servlets