So why are you asking? :) Do you really think that if the class is placed in the java.util package, then some kind of magic happens and its java code works in some complicated way?
It really just wraps all methods with a synchronized block {} and nothing more.
UPD: the difference is that you are much less likely to make a mistake if you use a synchronized collection instead of doing all the synchronization materials yourself.
UPD 2: as you can see in the sources, they use the "mutex'-object" as a monitor. When you use a synchronized modifier in a method signature (i.e. synchronized void doSmth() ), the current instance of your object (i.e. this ) is used as a monitor. The two blocks of code below are the same:
1.
synchronized public void doSmth () { someLogic (); moreLogic (); } synchronized public static void doSmthStatic () { someStaticLogic (); moreStaticLogic (); }
2.
public void doSmth () { synchronized (this) { someLogic (); moreLogic (); } } public static void doSmthStatic () { synchronized (ClassName.class) { someStaticLogic (); moreStaticLogic (); } }
Roman source share