¿Un ConcurrentHashMap necesita estar envuelto en un bloque sincronizado?
Realice todas las operaciones no de retiro en un ConcurrentHashMap (put()
, remove()
etc.) deben envolverse en unsynchronized(this)
¿bloquear? Entiendo que todas estas operaciones son seguras para subprocesos, entonces, ¿hay algún beneficio / necesidad real al hacerlo? Las únicas operaciones utilizadas sonput()
yremove()
.
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);
}
...
}