Synchronized understanding and usage

Lock:

1. Examples synchronization method, the lock is the current instance of the object

2. The synchronization method of the class, the class object is the current lock

3. The sync block, lock the object is inside the brackets

principle:

JVM built synchronized by use of lock, (monitor lock) Monitor the object is achieved by an internal, synchronized with the code block based on the entry and exit Monitor object implementation method, the monitor lock to achieve the underlying operating system dependent Mutex Lock (mutex) implementation, it is less a heavyweight lock performance

Guess you like

Origin www.cnblogs.com/kobe-lin/p/11681954.html