JProgrammer
JProgrammer

Reputation: 321

Why there is no AtomicBooleanArray datatype in Java?

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

Upvotes: 5

Views: 1141

Answers (2)

Peter Lawrey
Peter Lawrey

Reputation: 533920

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.

Upvotes: 3

Maxim Kirilov
Maxim Kirilov

Reputation: 2749

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?

Upvotes: 0

Related Questions