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();
        }
    }
}

 

posted @ 2019-09-18 11:10  菩提树下的丁春秋  阅读(741)  评论(1编辑  收藏  举报