Memory barriers and coding style over a Java VM

前端 未结 2 755
一整个雨季
一整个雨季 2020-11-28 20:33

Suppose I have a static complex object that gets periodically updated by a pool of threads, and read more or less continually in a long-running thread. The object itself is

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 21:00

    Having an immutable Foo with final a and b fields solves the visibility issues with the default values, but so does making theFoo volatile.

    Personally I like having immutable value classes anyway as they much harder to misuse.

提交回复
热议问题