2018-04-09

2018-04-09  本文已影响0人  寻亦追忆
public static void main(String[] args) {
        Map<String, Stu> map = new ConcurrentHashMap<>();
        map.put("stu", new Stu(1, "n1", 10));
        Stu stu = map.get("stu");

        for(int i=0;i<10000;i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    synchronized (stu) {
                        Integer age = stu.getAge();
                        stu.setAge(++age);
                    }
                }
            }).start();
        }



        System.out.println(map);
    }
上一篇下一篇

猜你喜欢

热点阅读