File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes HttpSession concept Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpSession concept" Watch "HttpSession concept" New topic

HttpSession concept

nippon ask

Joined: Nov 03, 2003
Posts: 2
Hi, i'm getting weird things on my user sessions, so i was wondering...
...Is the HttpSession thread-safe?
I'm having users objects 'setted' on other users sessions, so, may it be that i need to enclose the code in a 'synchronized' block?
I'll appreciate any help...
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Sessions are not automatically Thread-safe, but should be unique to individual users. Confusion of objects between users is almost certainly due to bad program architecture and will not be helped by synchronization.
The only time you should have to worry about synchronizing access to objects in sessions is when you have the possibility of processing multiple requests from the same user "at the same time" - for example with frames or where images are being generated.
I agree. Here's the link:
subject: HttpSession concept
It's not a secret anymore!