RedSpider1 / concurrent

这是RedSpider社区成员原创与维护的Java多线程系列文章。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

章节"11.4.1 获取资源"最后总结的流程图疑问

TeeMoCode opened this issue · comments

image

原图中acquire方法调用的tryAquire()方法,如果结果为true,自己中断线程;而查看AQS源码

public final void acquire(int arg) {
	if (!tryAcquire(arg) && acquireQueued(addWaiter(Node.EXCLUSIVE), arg))
	selfInterrupt();
}

可以看到如果tryAcquire()结果为true,那么!tryAcquire()的结果为false,不会执行 selfInterrupt();而是执行获取到锁后的代码

#47 已修复,直接关闭。