Thread-safe setting of a variable (Java)?

后端 未结 5 1142
我寻月下人不归
我寻月下人不归 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:49

    ConcurrentHashMp is:

    A hash table supporting full concurrency of retrievals and adjustable expected concurrency for updates. This class obeys the same functional specification as Hashtable, and includes versions of methods corresponding to each method of Hashtable. However, even though all operations are thread-safe, retrieval operations do not entail locking, and there is not any support for locking the entire table in a way that prevents all access. This class is fully interoperable with Hashtable in programs that rely on its thread safety but not on its synchronization details.

    The javadocs say that it's thread safe.

    Seems like a lot of work and CPU cycles to set configuration. Is it truly this dynamic? Or do you change once a month and just need a service bounce when you do?

提交回复
热议问题