Thread-safe setting of a variable (Java)?

后端 未结 5 1132
我寻月下人不归
我寻月下人不归 2020-12-11 15:59

Given the following code:

public class FooBar { 

  public static volatile ConcurrentHashMap myConfigData  = new ConcurrentHashMap();      

}

public class          


        
5条回答
  •  眼角桃花
    2020-12-11 16:34

    You could alway use AtomicReference if you feel unsure.

    Although I think in your case volatile schould be enough.

提交回复
热议问题