What is the difference between synchronized methods and blocks?
问题 What is the difference between synchronized methods and synchronized statements ? If possible, please use an example to make it more clear. 回答1: A synchronized method locks the monitor associated with the instance of the class (ie 'this') or the class (if a static method) and prevents others from doing so until the return from the method. A synchronized block can lock any monitor (you tell it which) and can have a scope smaller than that of the encolsing method. Synchronized blocks are