This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
How to Decide on Thread Safety
Posted by Bill Venners on April 11, 2000 at 9:21 PM
> I've read the article and still have a question. > How to judge if a class need to be thread-safe? > For example, I'm creating a servlet class A. > And inside A, it new other common class B and call > B's method. > Shall I make them thread safe? A and B? or just A? > And in some common Application, how to judge if they > need synchronized? > Well, I'd say that the only way to know whether to make a object thread safe or not is to know whether or not that object will ever be used by multiple threads at the same time. You have to know your application. Does your application contain multiple threads? Do any of those multiple threads share references to the same object at the same time? If so, that object should likely be thread safe. bv
Replies:
|