File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is session data thread safe?" Watch "Is session data thread safe?" New topic
Author

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?
Thanks.


BJ - SCJP and SCWCD
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 browser.you 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
Thanks.
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
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
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.
Bill
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 mail.yahoo.com, 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is session data thread safe?