ReentrantLock.LockInterruptibly 方法

定义

除非当前线程中断线程中断,否则获取锁。

[Android.Runtime.Register("lockInterruptibly", "()V", "GetLockInterruptiblyHandler")]
public virtual void LockInterruptibly();
[<Android.Runtime.Register("lockInterruptibly", "()V", "GetLockInterruptiblyHandler")>]
abstract member LockInterruptibly : unit -> unit
override this.LockInterruptibly : unit -> unit

实现

属性

例外

如果当前线程中断

注解

除非当前线程中断线程中断,否则获取锁。

如果锁未由另一个线程持有,并立即返回,则获取锁保留计数设置为 1。

如果当前线程已保存此锁,则保留计数将递增一个,该方法会立即返回。

如果锁由另一个线程持有,则当前线程会出于线程计划目的被禁用,并处于休眠状态,直到发生以下两种情况之一:

<ul>

<li>此锁由当前线程获取;或

<li>其他一些线程 Thread#中断中断当前线程。

</ul>

如果当前线程获取锁,则锁保留计数设置为 1。

如果当前线程:

<ul>

<li>在进入此方法时设置了中断状态;或

<li>是线程#中断在获取锁时中断的,

</ul>

然后 InterruptedException 会引发,并清除当前线程的中断状态。

在此实现中,由于此方法是显式中断点,因此优先响应对锁的正常或重新进入获取的中断。

Java文档java.util.concurrent.locks.ReentrantLock.lockInterruptibly()

本页的某些部分是根据 Android 开放源代码项目创建和共享的工作进行的修改,并根据 Creative Commons 2.5 属性许可证中所述的术语使用。

适用于