Possible Duplicate:
synchronized block vs synchronized method?
Hi all I was wondering is Snippet-A simply a syntax sugar for Snippet-B? :
Snippet A:
public synchronized void F() {
//..code
}
Snippet B:
public void F() {
synchronized (this) {
//..code
}
}
Or rather, what exactly is the difference between the two pieces of code above?
The two are identical. See §8.4.3.6 of the Java Language Specification (JLS):
In the example in the JLS, this:
is said to have the same effect as this:
and your two
Fmethods are very similar to the examplebumpmethods.