synchronized code : Synchronize « Thread « SCJP






synchronized methods prevent more than one thread from accessing an object's critical method code simultaneously.

The synchronized modifier applies only to methods and code blocks, not variables or classes.

synchronized methods can have any access control and can also be marked final.

Each object has just one lock.

Not all methods in a class need to be synchronized. 
A class can have both synchronized and non-synchronized methods.

If a thread goes to sleep, it holds any locks it has.

While only one thread can be accessing synchronized code.
Multiple threads can access the same object's unsynchronized code.

The main static methods in the Thread class are sleep, yield, and currentThread. 

If you have a synchronized method in a class, a subclass with an overriding method does not have to declare it as synchronized. 

The synchronized keyword affects only the code block in the original class.








7.9.Synchronize
7.9.1.synchronized code
7.9.2.Synchronize an entire method by putting the synchronized modifier in the method's declaration.
7.9.3.Synchronizing Part of a Method
7.9.4.An example for deadlock
7.9.5.To synchronize part of a method preceded by synchronized(this).
7.9.6.When used with a code block, synchronized must be applied to an object.