并发编程中的安全- public Holder holder;
-
- public void initialize() {
- holder = new Holder(42);
- }
-
- //Holder的代码
- public class Holder {
- private int n;
-
- public Holder() {this.n = n;}
-
- public void assertSanity() {
- if(n != n)
- throw new AssertionError("This statement is false.");
- }
- }
复制代码 当在多线程环境下执行不安全代码发布的方式,这样会抛出AssertionError么?里面的n!=n分别是什么含义?
|