Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Are Session attributes thread safe?

 
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 ]
 
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.
 
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. ???
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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.
 
Author and all-around good cowpoke
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
 
Marshal
Posts: 67387
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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 ]
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic