public class AtomicByteArray extends Object
byte
array in which elements may be updated atomically.
See the java.util.concurrent.atomic
package
specification for description of the properties of atomic
variables.
This is an adaptation of Java's AtomicIntegerArray for bytes.
Four bytes are packed into each int.
Only a few methods are implemented for now.Constructor and Description |
---|
AtomicByteArray(int length)
Creates a new AtomicByteArray of the given length, with all
elements initially zero.
|
Modifier and Type | Method and Description |
---|---|
byte |
addAndGet(int i,
int delta)
Atomically adds the given value to the element at index
i . |
boolean |
compareAndSet(int i,
byte expect,
byte update)
Atomically sets the element at position
i to the given
updated value if the current value == the expected value. |
byte |
decrementAndGet(int i)
Atomically decrements by one the element at index
i . |
byte |
get(int i)
Gets the current value at position
i . |
byte |
getAndAdd(int i,
int delta)
Atomically adds the given value to the element at index
i . |
byte |
getAndDecrement(int i)
Atomically decrements by one the element at index
i . |
byte |
getAndIncrement(int i)
Atomically increments by one the element at index
i . |
byte |
incrementAndGet(int i)
Atomically increments by one the element at index
i . |
int |
length()
Returns the length of the array.
|
void |
set(int i,
byte newValue)
Sets the element at position
i to the given value. |
public AtomicByteArray(int length)
length
- the length of the arraypublic void set(int i, byte newValue)
i
to the given value.i
- the indexnewValue
- the new valuepublic boolean compareAndSet(int i, byte expect, byte update)
i
to the given
updated value if the current value ==
the expected value.i
- the indexexpect
- the expected valueupdate
- the new valuepublic final byte getAndIncrement(int i)
i
.i
- the indexpublic final byte getAndDecrement(int i)
i
.i
- the indexpublic final byte getAndAdd(int i, int delta)
i
.i
- the indexdelta
- the value to addpublic final byte incrementAndGet(int i)
i
.i
- the indexpublic final byte decrementAndGet(int i)
i
.i
- the indexpublic final byte addAndGet(int i, int delta)
i
.i
- the indexdelta
- the value to addpublic byte get(int i)
i
.i
- the indexpublic int length()
Copyright © 2018. All rights reserved.