reentrant lock in java

 

First of all, the concept of reentrant locks means that a thread can enter any block of code synchronized by the lock it owns.

 

An example of a reentrant lock 

 

public class AccountService{

  private int account;
  
  private ReentrantLock lock = new ReentrantLock();

  public void inCreaseAccount(){
   
          lock.lock();
          account++;

          lock.unlock();
    
  }

}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326395708&siteId=291194637