Synchronized method / synchronized blocks
What is the difference between using the synchronized keyword to make a method synchronized and using synchronized blocks? The book that I have only offers a brief explanation of synchronized blocks that is semantically termed as, "a block that allows arbitrary code to be synchronized on the monitor of an arbitrary object."
Thanks in advance for any help.
[370 byte] By [
csano] at [2007-9-27 21:05:20]

Synchronizing an instance method is semantically equivanlent to synchronizing the entire body of that method on this.
Synchronizing a static method is semantically equivanlent to synchronizing the entire body of that method on the Class object representing the class that the method is defined in.
i.e., The following two classes are equivalent:
public class MyClass {
public synchronized void instanceMethod() {
//code...
}
public static synchronized void staticMethod() {
//code...
}
}
public class MyClass {
public void instanceMethod() {
synchronized (this) {
//code...
}
}
public static void staticMethod() {
synchronized (MyClass.class) {
//code...
}
}
}