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);
}
网友评论