问题
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