package devmanuals.com; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentHashMap; import java.util.Set; class CMRemove1 implements Runnable { ConcurrentMap cmp; String name; public CMRemove1(String name, ConcurrentMap cmp) { this.cmp = cmp; this.name = name; } public void run() { System.out.println(name + " maps the element "); cmp.put(1, "A"); cmp.put(2, "B"); cmp.put(3, "C"); cmp.put(4, "D"); System.out.println(cmp); System.out.println("Size of Map = " + cmp.size()); Set s = cmp.keySet(); System.out.println("Key set of map = " + s); try { Thread.sleep(400); } catch (InterruptedException e) { e.printStackTrace(); } } } class CMRemove2 implements Runnable { String name; ConcurrentMap cmp; public CMRemove2(String name, ConcurrentMap cmp) { this.cmp = cmp; this.name = name; } public void run() { try { boolean bol = cmp.remove(2, "B"); System.out .println(name + " deleted the given association : " + bol); Thread.sleep(1500); System.out.println(name + " deleted the association (2,''B'')then " + "remaining association of map = " + cmp); System.out.println("Remaining Set of key = " + cmp.keySet()); System.out.println("Remaining size of Map = " + cmp.size()); } catch (InterruptedException e) { e.printStackTrace(); } } } public class CMRemove { public static void main(String args[]) { ConcurrentMap cmp = new ConcurrentHashMap(); Runnable a = new CMRemove1("A", cmp); new Thread(a).start(); try { Thread.sleep(400); } catch (InterruptedException e) { e.printStackTrace(); } Runnable b = new CMRemove2("B", cmp); new Thread(b).start(); } }