> For the complete documentation index, see [llms.txt](https://hanfak.gitbook.io/workspace/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hanfak.gitbook.io/workspace/languages/java/advanced/concurrency-multithreading/mutual-exclusion/synchronized.md).

# Synchronized

* To help create locks
* Used with method
  * it automatically acquires the intrinsic lock for that method's object.
  * That will prevent other threads that invoke a synchronized method on the same object from interleaving execution.
  * When a thread tries to invoke a synchronized method while another thread is executing a synchronized method for that same object, the second thread will suspend execution until the first thread is done and exits.
  * links
    * <https://stackoverflow.com/questions/26245305/synchronised-instance-methods-in-java>
    * <https://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html>
* Statements
  * When creating an synchronized statement, you specify the object that will provide the intrinsic lock.
  * Before a thread can execute the code contained within the synchronized statement, it must first acquire the intrinsic lock associated with the specified object and then when the thread is done, it will release its hold on that lock.
* <https://dzone.com/articles/how-synchronization-works-in-java-part-1>
* <https://dzone.com/articles/how-synchronization-works-in-java-part-2>
