Correct way of making a singleton a Spring bean

前端 未结 6 780
野性不改
野性不改 2020-12-08 03:12

I am converting a singleton to a Spring bean, so that if the singleton fails to initialize, then entire web application\'s spring context doesn\'t load properly.

Th

6条回答
  •  醉梦人生
    2020-12-08 03:38

    You must declare the INSTANCE field as volatile for double-checked locking to work correctly.

    See Effective Java, Item 71.

提交回复
热议问题