hashmap1.7的死锁模拟
package com.cxy.springdataredis.hashmap; import javax.lang.model.element.VariableElement; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; public class Mythread implements Runnable { public static Map<Integer,Integer> map= new HashMap<Integer,Integer>(2); public static AtomicInteger atomicInteger= new AtomicInteger(); @Override public void run() { while (atomicInteger.get()<10000){ map.put(atomicInteger.get(),atomicInteger.get()); atomicInteger.incrementAndGet(); } } }
package com.cxy.springdataredis.hashmap; public class ThredDemo { public static void main(String[] args) { for (int i =0;i<10;i++){ new Thread(new Mythread()).start(); } } }
笔记转移,由于在有道云的笔记转移,写的时间可能有点久,如果有错误的地方,请指正