Why there is no AtomicBooleanArray datatype in Java?

我的梦境 提交于 2019-12-06 03:22:07

问题


I have noticed that there is NO AtomicBooleanArray datatype in Java similar to the AtomicIntegerArray. Although I can use AtomicBoolean[] for my current needs, I was curious to get an understanding as to why AtomicBooleanArray is NOT part of the library.

Any thoughts in this would be much appreciated.

Thanks


回答1:


AtomicBoolean actually wraps a int which is set to 0 or 1 for false or true. This is because it uses compareAndSwap methods which are int based, and not smaller.

You could implement an AtmoicBooleanArray, but not cleanly which is perhaps why it is not there. i.e. the JVM doesn't support atomic boolean operations because the CPUs like x64 and ARM don' support it.




回答2:


I think that since AtomicIntegerArray can be see as AtomicBooleanArray, if you will assign only 0 (false) and 1 (true) values. So why to write duplicate code?



来源:https://stackoverflow.com/questions/19379548/why-there-is-no-atomicbooleanarray-datatype-in-java

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