class.
Read the articles on concurrency by Brian Goetz in IBM DeveloperWorks,
and his book /Java Concurrency in Practice/.
This is the best advice. =9AThread safety is complicated enough that a
couple of quick posts on Usenet won't explain everything. =9AYou need
something more thorough to give you the full picture. =9AJava Concurrency
in Practice will give an excellent understand of many thread safety and
concurrency issue.
Case in point:
=9A>> public class ThreadSafe {
=9A>>
=9A>> =9A =9A private Vector<String> vector;
=9A>> =9A =9A /** But is OK to have such method? */
=9A>> =9A =9A public Vector<String> getVector() {
=9A>> =9A =9A =9A =9A return vector;
=9A>> =9A =9A }
=9A>> }
Nope, not ok. =9AYou created an object on one thread (not shown) and then
tried to fetch it on another. =9AGuaranteed problems. =9AExample:
Let's say ThreadSafe has a constructor which Thread A calls:
=9A =9Apublic ThreadSafe() {
=9A =9A =9Avector = new Vector<String>();
=9A =9A}
Now Thread B calls getVector. =9AOops!! =9AIt may not even see the value =