views:

142

answers:

2

Hi, would you please explain more about the meaning of synchronization?

+8  A: 

Synchronization is the way two or more threads can safely access shared resources without overwriting each other's work.

http://java.sun.com/docs/books/tutorial/essential/concurrency/sync.html

Robert Harvey
Also, take a look at http://en.wikipedia.org/wiki/Synchronization_(computer_science)
Rory
Sun's tutorial is quite good. However, note that in the tutorial, "Synchronization" is one of the chapters in the "Concurrency" lesson. I suggest starting from the beginning of the lesson: http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html
Eli Acherkan
The other option is using java.util.concurrent Atomic primitives, which can be used to implement STM, which lowers the cost of synchronization.
Yann Ramin
A: 

You need to use Synchronization if work in multi threaded environment. Local variables inside methods are thread safe. If you are using global variables (including class level variables) you need to synchronize the method.

fastcodejava