我有下面的代码,添加看起来对我来说是线程安全的。modifyelement 怎么样,或者我怎样才能使这个线程安全?
ConcurrentNavigableMap<String, List<String>> entries = new ConcurrentSkipListMap<>();
public void record(String key, String value) {
entries.computeIfAbsent(key, k -> Collections.synchronizedList(new ArrayList<String>())).add(value);
}
public void modifyelement(String key, String oldval, String newval) {
entries.computeIfPresent(key, (k , v ) -> {
v.set(v.indexOf(oldval), newval);
return v;
});
}