Not thread-safe Object publishing

前端 未结 7 2108
眼角桃花
眼角桃花 2020-12-02 21:44

Reading \"Java Concurrency In Practice\", there\'s this part in section 3.5:

public Holder holder;
public void initialize() {
     holder = new Holder(42);
}         


        
7条回答
  •  失恋的感觉
    2020-12-02 22:04

    looking at this from a sane perspective, if you assume that the statement

    if(n != n)

    is atomic (which I think is reasonable, but i dont know for sure), then the assertion exception could never be thrown.

提交回复
热议问题