我看到了:
// thread is a member of this class
synchronized( this.thread )
{
this.thread.running = false;
this.thread.notifyAll(); // Wake up anything that was .waiting() on
// the thread
this.thread = null; // kill this thread reference.
// can you do that in a synchronized block?
}
可以设置
thread=null
并保持锁定状态吗?我在BB代码中找到了这个块。
最佳答案
是的,没关系。同步语句将获取其锁定的引用的副本,并使用该副本计算出最终要解锁的内容。
实际上,Java语言规范的Section 14.19尚不清楚,但是它确实声明了表达式是在开始时求值的,并且以后也不会再对它求值了。