aspose file tools*
The moose likes JSP and the fly likes Newbie question on state management Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Newbie question on state management" Watch "Newbie question on state management" New topic
Author

Newbie question on state management

peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
I am newbie in web programming, I known HTTP protocol is stateless, and I know we can use session attribute to store the state of user, but I read "Head first Servlets & JSP" and it mentioned that even session attribute is not thread safe because the same user can open more than one browser, so if session attribute is not thread safe, then how should we keep the state of user?
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

Using the session object is the best way to keep the state of the user.

Yes the session object is not thread safe. In many cases it does not matter that the session object is not thread safe.
In case the session object is holding critical data like say a shopping cart where thread safety is important you need to make sure that all your code that access the session object is synchronized!

The session object not being thread safe is only a warning for you to make sure that you write code in a manner that makes the session object thread safe to access. Any alternate means to track session will also face the same issue!


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Crossposted: http://forums.sun.com/thread.jspa?threadID=5368191
Please read this: http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie question on state management
 
Similar Threads
Is session attribute thread-safe?
how we can make a session object thread safe?
servlet session thread safety ?
Objective 7.1
I know local objects are thread safe. But why not obj here too?