Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Servlets and the fly likes Is session data thread safe? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is session data thread safe?" Watch "Is session data thread safe?" New topic

Is session data thread safe?

Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 671
My feeling is that it is safe since only one user (one browser window) can send one request at a time.
One book says multiple browsers share one session. I can not figure it out.
Any thoughts?

We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
According to the Servlet 2.3 specs:

SRV.7.7.1 Threading Issues
Multiple servlets executing request threads may have active access to a single session object at the same time. The Developer has the responsibility for synchronizing access to session resources as appropriate.
guo mark
Ranch Hand

Joined: Oct 20, 2001
Posts: 43
each user own a session but not each may get a session shared by several browser source from some single page(for example you chick a hyperlink and open a new page in a new windon).
It is that you mean?

meet once ,love every while
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 671
I open multiple windows and they all have different sessions.
Now I will try open new windows from a window (by click a link). Maybe these windows will share the same session.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12910
You might have multiple requests from the same window executing at the same time. For example a page with frames may generate several requests, or one that gets dynamically generated images.
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Different browser windows opened by the same user and belong to the same session is extremely common.
Just use your yahoo account, log in, then if you click the browser icon on your desktop, you get another session, to verify it, you found you need to re-login.
However, if you open a new browser from the already-login browser window File->New->Window, you have 2 browser windows but the same session, to verify it, you found you do not need to re-login. You can do many things with the same or different pages concurrently.
[ August 19, 2002: Message edited by: Roseanne Zhang ]
Consider Paul's rocket mass heater.
subject: Is session data thread safe?