This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Are Session attributes thread safe?  RSS feed

 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that Context attributes are not thread safe. But why session attributes are not thread safe? Could anyone explain me the reason for it. And also why only Request attributes and local variables are thread safe Please explain me the concept. Thanks in advance.
[ July 24, 2007: Message edited by: David O'Meara ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a single user makes two requests at the same time (eh if they opened two browser windows after logging in) then both request threads will access the same session object at he same time.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Siddharth,

Its a good idea to search the forum for similar posts before posting the question.

This question has been discussed many times in this forum.
This
is a question posted by some other rancher before.
You can search for similar threads if not satisfied with this one.
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the user opened 2 browser windows then that means 2 different sessions so howcome they both request threads that will access the same session object at the same time. Not clear....And what about request attributes and local variables. ???
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two browsers does not necessarily mean two sessions.

MSIE, for instance, behaves differently depending on how you open the second window. If you use the Windows Start button to open a new instance, you will get an instance with it's own cookie space. If, on the other hand, you use Ctrl+N or the File -> new menu option from within MSIE, the new instance will share the same cookie space, and thus be a part of the same session as the first instance.


Another more common way to have multiple simultaneous request is a page with frames, iframes, or a page that makes AJAX requests.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is easy to create a web page that makes multiple requests for content from the same servlet, therefore you can NOT automatically assume that session contents are "thread safe."

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multiple windows, frames, iframes, and Ajax are all ways that multiple requests can be made within the same session.

[Edit; OK, so Ben already said the same thing. Do you expect me to actually be able to read first thing in the morning?]
[ July 24, 2007: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!