remove() 메소드를 사용하고 있습니까? 동기화 메서드가 remove 메서드에 추가되지 않은 기사를 읽었습니다. ConcurrentHashMap에서 특정 항목을 올바르게 제거하려면 어떻게합니까?Java ConcurrentHashMap에서 특정 항목 제거
예제 코드 :
ConcurrentHashMap<String,Integer> storage = new ConcurrentHashMap<String,Integer>();
storage.put("First", 1);
storage.put("Second", 2);
storage.put("Third",3);
//Is this the proper way of removing a specific item from a tread-safe collection?
storage.remove("First");
for (Entry<String, Integer> entry : storage.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
// ...
System.out.println(key + " " + value);
}
"나는 그 동기가 remove 메소드에 추가되지 않은 기사를 읽었습니다"이었다 그 기사는 자바 5,6,7, 또는 8의 시대에 대해 작성된거야? 어쩌면 오래된 Java 버전을 염두에두고 작성했을 수도 있습니다. –
이 링크는 http://javarevisited.blogspot.ca/2013/02/concurrenthashmap-in-java-example-tutorial-working.html에서 정상적으로 작동합니다. 그는 "put(), remove(), putAll() 또는 clear()와 같은 업데이트 작업이 동기화되지 않기 때문에 자세한 내용을 읽어보십시오. http://javarevisited.blogspot.com/2013/02/concurrenthashmap-in-java- example-tutorial-working.html # ixzz3OM79B2ol " –
@ peter.petrov - 코드 예제에서와 같이 ConcurrentHashMap에서 remove 메서드를 호출하면 괜찮습니까? thread-safety는 문제가되지 않아야합니까? –