Initially, the article introduces synchronized methods - therefore, up to this point, the reader may believe that the unit of synchronization granularity is the only method.
Indeed, if there are no synchronized blocks / operators, the above example can only be performed as:
public void addName(String name) { doSyncAdd(name); nameList.add(name); } private synchronized void doSyncAdd(String name) { lastName = name; nameCount++; }
Thus, synchronized statements mean that you can save related code that needs to be synchronized internally. Instead of declaring a separate method that both pollutes the namespace, it also fragmentes the code stream. (Well, factoring methods are good in moderation, but it's better to have a choice.)
source share