本文介绍了为什么Java中没有AtomicBooleanArray数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经注意到,Java中与AtomicIntegerArray类似的AtomicBooleanArray数据类型为 NO .尽管我可以根据当前需要使用AtomicBoolean [],但我很好奇为什么AtomicBooleanArray不属于库的一部分.

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.

谢谢

推荐答案

AtomicBoolean实际上包装了一个int,它为false或true设置为0或1.这是因为它使用基于int且不较小的compareAndSwap方法.

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.

您可以实现AtmoicBooleanArray,但不能完全实现,这也许就是为什么它不存在的原因.即JVM不支持原子布尔操作,因为x64和ARM之类的CPU不支持它.

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.

这篇关于为什么Java中没有AtomicBooleanArray数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 22:35