Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Reentrant Locks - Part IV

The locks created using the synchronized keyword in Java are reentrant; they are also known as intrinsic or monitor locks. Here's how reentrant synchronization works:

class ReentrantIntrinsicLockExample {
  private final Object intrinsicLock = new Object();
  
  public void foo() {
    synchronized (intrinsicLock) {
      // ...
      bar();
    }
  }
  
  public void bar() {
    synchronized (intrinsicLock) {
      // ...
    }
  }
}
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content