【发布时间】:2014-11-17 20:42:21
【问题描述】:
ConcurrentHashMap(put()、remove() 等)上的所有非检索操作是否需要包装在 synchronized(this) 块中?我知道所有这些操作都是线程安全的,那么这样做有什么真正的好处/需要吗?唯一使用的操作是put() 和remove()。
protected final Map<String, String> mapDataStore = new ConcurrentHashMap<String, String>();
public void updateDataStore(final String key, final String value) {
...
synchronized (this) {
mapDataStore.put(key, value);
}
...
}
【问题讨论】:
标签: java synchronized concurrenthashmap