您的位置:首页 > 其它

ReentrantLock

2015-10-02 09:57 387 查看
ReentrantLock:
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/ReentrantLock.html#lockInterruptibly()
public void lockInterruptibly()
throws InterruptedException

Acquires the lock unless the current thread is interrupted.
Acquires the lock if it is not held by another thread and returns immediately, setting the lock hold count to one.

If the current thread already holds this lock then the hold count is incremented by one and the method returns immediately.

If the lock is held by another thread then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:

The lock is acquired by the current thread; or

Some other thread interrupts the current thread.

If the lock is acquired by the current thread then the lock hold count is set to one.

If the current thread:

has its interrupted status set on entry to this method; or

is interrupted while acquiring the lock,

then
InterruptedException
is thrown and the current thread's interrupted status is cleared.
In this implementation, as this method is an explicit interruption point, preference is given to responding to the interrupt over normal or reentrant acquisition of the lock.

Specified by:
lockInterruptibly
in interface
Lock
Throws:
InterruptedException
- if the current thread is interrupted
Thread interrupt:
http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#interrupt()
If this thread is blocked in an invocation of the
wait()
,
wait(long)
, or
wait(long, int)
methods of the
Object
class, or of the
join()
,
join(long)
,
join(long, int)
,
sleep(long)
, or
sleep(long, int)
, methods of this class, then its interrupt status will be cleared and it will receive an
InterruptedException
.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: