got it. Thanks Ian
在 2018年12月7日星期五 UTC+8下午12:59:49,Ian Lance Taylor写道:
>
> On Thu, Dec 6, 2018 at 8:45 PM Chao Yuepan > wrote:
> >
> > Java implements singleton by double-checking must use keyword volatile :
> >
> >
> > class Foo {
> > private volatile Bar bar;
> >
> > public Bar getB
On Thu, Dec 6, 2018 at 8:45 PM Chao Yuepan wrote:
>
> Java implements singleton by double-checking must use keyword volatile :
>
>
> class Foo {
> private volatile Bar bar;
>
> public Bar getBar() {
> Bar value = bar;
> if (value == null) {
> synchronized (this) {
> value
Java implements singleton by double-checking must use keyword volatile :
class Foo {
private volatile Bar bar;
public Bar getBar() {
Bar value = bar;
if (value == null) {
synchronized (this) {
value = bar;
if (value == null) {
bar = value = computeBar(