The list of methods to do AtomicInteger are organized into topic(s).
void
addNodeUse(String nodeInfo) add Node Use
AtomicInteger cnt = (AtomicInteger) nodeExecMap.get(nodeInfo);
cnt.incrementAndGet();
nodeExecMap.put(nodeInfo, cnt);
int
bitwiseOrAndGet(final AtomicInteger ai, final int toOrValue) Atomically do bitwise OR between the value in the AtomicInteger and the toOrValue, and set the new value to the AtomicInteger and also return the new value.
int oldValue = ai.get();
int newValue = oldValue | toOrValue;
while (oldValue != newValue && !ai.compareAndSet(oldValue, newValue)) {
oldValue = ai.get();
newValue = oldValue | toOrValue;
return newValue;
int
count() count
return COUNTER.getAndIncrement();
int
count(byte[] array, byte value) Returns the number of the elements in the specified array that equal the specified value.
int cnt = 0;
for (byte i : array) {
if (i == value) {
++cnt;
return cnt;
boolean
countDownToZero(AtomicInteger counter) Decreases counter to zero, or does not change the counter if negative.
for (;;) {
int c = counter.get();
if (c > 0) {
int newCounter = c - 1;
if (counter.compareAndSet(c, newCounter)) {
return newCounter == 0;
} else {
...
Map
countOccurrences(final Collection collection)
Count the number of occurrences in a given collection.
final Map<T, AtomicInteger> map = new HashMap<T, AtomicInteger>();
for (final T instance : collection) {
final AtomicInteger counter = map.get(instance);
if (counter == null) {
map.put(instance, new AtomicInteger(1));
} else {
counter.incrementAndGet();
return map;
String
create() Returns a unique identifier.
return create("");
String
createIdentifier(Class> clazz) Creates a unique identifier for the given class.
synchronized (counterMap) {
AtomicInteger counter = counterMap.get(clazz);
if (counter == null) {
counter = new AtomicInteger(0);
counterMap.put(clazz, counter);
return String.format("%08x", counter.getAndIncrement());
ThreadFactory
createThreadFactory(final String prefix) create Thread Factory
return new ThreadFactory() {
private AtomicInteger size = new AtomicInteger();
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setName(prefix + size.incrementAndGet());
if (thread.isDaemon()) {
thread.setDaemon(false);
return thread;
};