猿问

Java集合 modCount为什么不用volatile修饰?

2个线程 访问一个list 其中一个remove操作了 另一个在迭代 假如不用vol修饰 那么在迭代的那个线程可能感知不到modcount的变化啊
甚至于说官方认为有volatile是一个BUG?https://bugs.java.com/bugdata...

犯罪嫌疑人X
浏览 555回答 2
2回答

慕容3067478

Since the modCount mechanism comes with no guarantees, and users ofsingle-threaded collections do not expect to pay the (high) priceof a volatile write on every modification operation, the volatilemodifier should be removed.Description里都写的那么清楚了 还有什么可问的?
随时随地看视频慕课网APP

相关分类

Java
我要回答