Study Notes (17): 19 years and principles of concurrent programming video training tutorials entry to the master - in-depth understanding of the synchronized keyword ...

Learning immediately: https://edu.csdn.net/course/play/9827/208794?utm_source=blogtoedu

Built-in lock

    Each java object can be used as a synchronization lock to achieve, these locks are called built-in lock. When a thread enters a synchronized block or method of automatically acquire the lock, when you exit the synchronized block or method will release the lock. The only way to get the lock is built into this code block or method with fuzzy protected lock.

Mutex

    Built-in lock is a mutex, which is meant at most only one thread can acquire the lock when thread A thread B attempts to get hold of the built-in lock, thread A must wait or block until the thread B releases the lock, If the thread does not release the lock B, then A thread will wait forever.

Modification of the conventional method: Example locked object

Modification of the conventional method: lock the entire class

 Modifying the code block: synchronized lock to lock an object (Lock) i.e. synchronized parentheses after the contents

Published 22 original articles · won praise 21 · views 258

Guess you like

Origin blog.csdn.net/weixin_45831970/article/details/104375765