Java concurrency: is final field (initialized in constructor) thread-safe?

后端 未结 9 1066
暖寄归人
暖寄归人 2020-11-29 08:35

Can anyone tell me whether this class is threadsafe or not ?

class Foo {

    private final Map aMap;

    public Foo() {
        aMap =         


        
9条回答
  •  一向
    一向 (楼主)
    2020-11-29 08:58

    This class has no concurrency issue cause you expose only a get method. If you add some method that modify the map you have to mark this method as synchronized.

提交回复
热议问题