美文网首页
2018-04-09

2018-04-09

作者: 寻亦追忆 | 来源:发表于2018-04-09 13:19 被阅读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);
    }

相关文章

网友评论

      本文标题:2018-04-09

      本文链接:https://www.haomeiwen.com/subject/afqihftx.html