File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Thread-safety Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Thread-safety" Watch "Thread-safety" New topic
Author

Thread-safety

John Daniel
Greenhorn

Joined: Mar 27, 2005
Posts: 20
I'm a Java newbie writing a small web application. I've been reading K&B's HF Servlet and JSP book at night in my attempt to catch up on the technology. Anyway in chapter 5, Kathy makes it very clear that servlet instance variables are not thread-safe. I understand that. But what I'm not clear on is what about instance variables of new'ed POJ classes? If my servlet instantiates a class containing instance variables, are those instance variables thread-safe? jd
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56185
    
  13

Yes, unless you do something like store a reference to them in a servlet instance variable.

When you instantiate an object and store it in a thread-safe reference, such as a method-local variable, other threads have no way to "get at" the instance. Ergo, thread-safe.
[ October 19, 2006: Message edited by: Bear Bibeault ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
John Daniel
Greenhorn

Joined: Mar 27, 2005
Posts: 20
Thank you, that's what I wanted to know. jd
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Thread-safety
 
Similar Threads
Class and instance variables...
final instance variables
Multi thread servlets and the Server applications they call.
Thread Safe Instance Variables
Deleting session deletes all my sessions