If you want to synchronize all the methods in your class, you will have to use the keyword synchronized on every method. Carefully decide whether it's necessary to synchronize a method though. Some don't need it, and synchronizing them will add an unnecessary performance penalty.
You can also synchronize your code by making your fields volatile. This however, will not stop race conditions from occurring, and you will have to add a kind of mutex to your code. You will have to use the wait() and notiftyAll() methods to carefully direct which parts of your code can be accessed by which threads. This is a very painful process, and this is why it's not wise to replace the synchronized keyword.
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Joined: May 13, 2010
offtopic.regarding the extra post. i could not see any option to delete the post.Sorry for that.
Thank You for explanation.
We say vector is thread safe.So how vector class was written
from your explanation what i see is each method of vector class must be synchronized but when i went through signature in javadocs i did not find synchronized keyword on method signature.