What is the meaning of “ReentrantLock” in Java?

后端 未结 6 1963
故里飘歌
故里飘歌 2020-11-30 22:18

Reentrancy means that locks are acquired on a per-thread rather than per-invocation basis.

Since an intrinsic lock is held by a thread, doesn\'t it mean that a threa

6条回答
  •  星月不相逢
    2020-11-30 22:44

    it's about recurse, think about:

    private lock = new ReentrantLock();
    public void method() {
          lock.lock();
          method();
    }
    
    

    If the lock is not re-entrant able, the thread could block itself.

提交回复
热议问题