ReentrantLock
2015-10-02 09:57
387 查看
ReentrantLock:
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/ReentrantLock.html#lockInterruptibly()
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
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:
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
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
InterruptedExceptionis 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:
lockInterruptiblyin interface
LockThrows:
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
Objectclass, 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.
相关文章推荐
- 程序员可能常犯的 6 个错误
- Word Break II
- Task-based Asynchronous Operation in WCF z
- task可声明参数 z
- IOS面试题汇总(中英文)
- String构造函数originalValue.length>size 它发生
- Git 添加远程库
- Detecting Client Connection in WCF Long Running Service (Heartbeat Implementation) z
- Java基础知识强化之集合框架笔记15:List集合的特点
- 文章标题
- JavaScript斐波纳契数列非递归算法
- C 源码学习——memcpy函数
- 腾讯IEG面试失败经验总结
- 记一次腾讯IEG面试失败经历
- MarkDown 语法
- 计算器
- 购买开发者账号 和 真机调试、打包、跳转AppStore评分、上架、内购细节
- [python爬虫] Selenium定向爬取海量精美图片及搜索引擎杂谈
- 无法嵌入互操作类型“Excel.ApplicationClass”。请改用适用的接口。
- Java 常见异常及趣味解释