Idiomatic use of ReentrantLock in Concurrency package [duplicate]

别说谁变了你拦得住时间么 提交于 2019-12-03 21:37:33

Ben Manes linked to a discussion in the comments that talks about JIT optimisation. Apparently the hotspot compiler will not optimise the loads of a final field because it can be modified via reflection or with the Unsafe class.

Therefore this mechanism gives a minor speed improvement allowing JIT to optimise loads of the lock instance. They didn't go into detail of which optimisation would occur, but I suspect the optimisation is for preventing reloading the instance from main memory. This would allow a Thread to use the Re-entrant lock multiple times without penalty.

Unfortunately this answer is speculation based upon a mailing list discussion. If someone can correct me please go ahead!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!