一个Java线程可以获得一个锁,而已经拥有它?

一个Java线程可以获得一个锁,而已经拥有它?

问题描述:

如果线程持有锁定,当线程需要进入由同一个锁定控制的另一个临界区时会发生什么? p>

If a thread holds a lock , what happens when the thread needs to enter another critical section controlled by the same lock?

在Java中的内部锁(同步)是可重入的,因此JVM将认识到当前线程已经持有这个锁,它将继续。

Intrinsic locks (synchronized) in Java are reentrant, thus the JVM will recognize that the current thread already holds this lock and it will proceed.

还有显式锁,即可重入。

如果锁不可重入,则可以不使用递归方法。

If a lock is not reentrant, you could for instance not use recursive methods.