Meaningless Drivel is fun!*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "what r thread safe variables " Watch "what r thread safe variables " New topic
Author

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
4.request,session
5.request,session,local
6.session,local
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
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
Bill
Jeroen Wenting
Ranch Hand

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


42
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what r thread safe variables
 
Similar Threads
Is session object thread safe.
Thread Safe
Help w/SingleThreadModel
Thread safe servlets
Mock Question about thread-safe