import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; public class Example { public static void main(String[] args) { ConcurrentLinkedHashMap<String, Integer> map = new ConcurrentLinkedHashMap.Builder<String, Integer>() .build(); for (int i = 0; i < 10; i++) { final int threadId = i; new Thread(() -> { for (int j = 0; j < 1000; j++) { String key = "Key-" + threadId + "-" + j; int value = threadId * j; map.put(key, value); Integer retrievedValue = map.get(key); System.out.println("Thread " + threadId + ": " + retrievedValue); } }).start(); } } }


上一篇:
下一篇:
切换中文