Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Is session attribute thread-safe?  RSS feed

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I visit the same web application across two browser windows simultaneity, there will be two threads visiting the web application.
But I don't know whether the two threads share the same session?
If they share, the session attribute is not thread-safe.
If they do not share, the session attribute is thread-safe.
who can explain it to me?
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The requests from different browser instances (other than opening a new window form an existing one) will have diferent sessions.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 'two browser windows sharing session' debate always seems to relate to how 'well behaved' your particular browser is.

I think it was Netscape 4.x that would simply NOT be able to have two different sessions.

Also, current versions of IE will *always* share a session if you use "File|New|Window", "Cntrl-N" or any other variation of opening a second window from an existing window.

If, on the other hand, you click the Start Menu icon twice, or you click the QuickLaunch toolbar icon twice, then you will get two windows of IE that know nothing about each other, and will NOT share a session.


As for thread safety, the issue *can* be most easily demonstrated by having two browser windows that share a session. But it's not limited to this case.
 
Ranch Hand
Posts: 8934
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 2 browsers will represent 2 sessions.
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Mike Curwen:
If, on the other hand, you click the Start Menu icon twice, or you click the QuickLaunch toolbar icon twice, then you will get two windows of IE that know nothing about each other, and will NOT share a session.


It's very good infomation... I've never known it b4... I think the following thread might be useful to the original poster as well....
http://www.coderanch.com/t/357781/Servlets/java/block-multiple-logins-same-user
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply put:
if there are two instances of the browser executable running on the client, each of which accesses the web application, those two should have two distinct sessions (indeed Netscape 4 may have been extremely misbehaved in this, but it is possible that it simply was too smart for itself and started another window in the same instance whenever you thought you were launching a new instance).
If there are two windows running in the same browser instance both will share the session.
You can easily check this on Windows in the taskmanager.
Launch IE and you will see a task 'iexplore.exe' appearing. Open a new window from the menu (or click Ctrl-N), no new task will appear.
Kill the task and both windows disappear.
Now launch IE twice from the desktop, quicklaunch bar or startmenu. You'll see 2 tasks 'iexplore.exe'.
 
Author
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But this doesn't make your sessions thread safe. If you 'refresh' the window this sends a request to the server which could access the session, hitting refresh again before the first request finishes will send another request to the server and more session access.
Never rely on thread safety in sessions, always synchronize
 
Pradeep bhatt
Ranch Hand
Posts: 8934
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Kevin Jones:
But this doesn't make your sessions thread safe. If you 'refresh' the window this sends a request to the server which could access the session, hitting refresh again before the first request finishes will send another request to the server and more session access.
Never rely on thread safety in sessions, always synchronize


In case we use frames we encounter synchronization problem.
[ January 30, 2004: Message edited by: Pradeep Bhat ]
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any web page generation that involves multiple simultaneous requests will have to watch out for synchronization problems. Not only frames but also images or other resources generated on the fly can cause a servlet to be processing multiple requests from the same browser instance "at the same time."
Bill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!