<分区>
Java concurrency in practice book已经给出了不安全发布的例子
public class Holder
{
private int n;
public Holder(int n)
{
this.n = n;
}
public void assertSanity()
{
if (n != n)
throw new AssertionError("This statement is false.");
}
}
上面的代码看起来是线程安全的。如果 n 是公共(public)变量,它就不是线程安全的。书上的例子错了吗?