同步和只读Map

来源:互联网 发布:电信网络维修 编辑:程序博客网 时间:2024/06/05 05:55

One way to be more confident that the map is not modified during the"read-only" phase is to divide the application into two phases withtwo different maps: First populate the map with a thread-safe implementationlike

m = Collections.synchronizedMap(new HashMap());

then make an immutable copy using

m2 = Collections.unmodifiableMap(new HashMap(m));

原创粉丝点击