jjzjj

AtomicIntegerArray

全部标签

java - 这是 "better"。 AtomicIntegerArray(1/0 为真/假)与 AtomicBoolean[]?

我对此很好奇。如果使用值为0和1的AtomicIntegerArray,则可以完成与AtomicBoolean数组相同的操作。示例:finalAtomicIntegerArrayarray1=newAtomicIntegerArray(10);array1.compareAndSet(3,0,1);//0=falseand1=true//exactlythesamethingof:finalAtomicBoolean[]array2=newAtomicBoolean[10];for(inti=0;i你认为哪个更快更好? 最佳答案 W

java - AtomicIntegerArray 与 AtomicInteger[]

AtomicIntegerArray和AtomicInteger[]的含义有区别吗?哪个使用起来更快?(我唯一注意到的是first占用的空间要少得多,但这意味着每次重新检查都会检查数组的边界,所以这会使速度变慢?)编辑:在数组被预初始化的情况下。 最佳答案 AtomicInteger[]将需要每个元素一个对象。AtomicIntegerArray只需要AtomicIntegerArray对象和一个数组对象。所以尽可能使用后者。即使对于普通数组,边界检查的成本也非常小。可能重要的是,从多个处理器访问同一缓存行中的数据可能会导致严重的性