my dog learned polymorphism
The moose likes Servlets and the fly likes what r thread safe variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "what r thread safe variables " Watch "what r thread safe variables " New topic

what r thread safe variables

kesava chaitanya
Ranch Hand

Joined: Aug 15, 2001
Posts: 140
what r thread safe variables and why in the below options?
if i write multi threaded servlet which of the variables are threadsafe?
1.request variables
2.session varaibles
3.local variables
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
1.request variables - The request object is unique to the Thread executing the service and is not shared by any other threads.

2.session variables - Watch out for possible conflicts if your application generates more than one request "at the same time" - for example if you are using frames or generating images. In that case, the same session is in use in multiple requests.

3.local variables - visible only to the Thread executing the method. However, if you assign a reference to a more visible object to a local variable, it is unsafe.

... I don't understand the intent of 4,5,6
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
r and i are not threadsafe, are and I maybe.

I agree. Here's the link:
subject: what r thread safe variables
It's not a secret anymore!