import java.util.*;
import java.util.Map.*;
import java.util.concurrent.*;

class Main {
    public static void main(String[] args) throws InterruptedException {
        Map<String, String> m = new ConcurrentHashMap<>();
        int n = 10;
        for (int i = 0; i < n; ++i) {
            m.put("key" + (i + 1), "value" + (i + 1));
        }
        System.out.println(m.size());
        Runnable r = () -> { 
            for (Entry<String, String> e : m.entrySet()) {
                System.out.println("Removing: " + e.getKey() + " -> " + e.getValue());
                m.remove(e.getKey());
            }
        };
        Thread[] ts = new Thread[n];
        for (int i = 0; i < n; ++i) {
            ts[i] = new Thread(r);
        }
        for (int i = 0; i < n; ++i) {
            ts[i].start();
        }
        for (int i = 0; i < n; ++i) {
            ts[i].join();
        }
        System.out.println(m.size());
    }
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: