原因:synchronized(Integer)时,当值发生改变时,基本上每次锁住的都是不同的对象实例,想要保证线程安全,推荐使用AtomicInteger之类会更靠谱。使用System.identityHashCode(obj)可以得到根据物理地址算出的hash值。
java核心-多线程-零碎知识收集
原文:https://www.cnblogs.com/leeethan/p/10960060.html