import java.util.Map; import java.util.HashMap; // This program demonstrates why concurrent collections are // better suited for concurrent applications. // Using HashMap prevents this program from terminating. class RegularMap { static Map points; static void read(String key) { Point v; while ((v = points.get(key)) == null); System.out.println(v); } public static void main(String[] args) throws InterruptedException { String key = "hello"; points = new HashMap<>(); Thread t = new Thread(() -> read(key)); t.start(); Thread.sleep(100); points.put(key, new Point(2, 2)); t.join(); } }