Java Utililty Methods AtomicInteger

List of utility methods to do AtomicInteger

Description

The list of methods to do AtomicInteger are organized into topic(s).

Method

voidaddNodeUse(String nodeInfo)
add Node Use
AtomicInteger cnt = (AtomicInteger) nodeExecMap.get(nodeInfo);
cnt.incrementAndGet();
nodeExecMap.put(nodeInfo, cnt);
intbitwiseOrAndGet(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;
intcount()
count
return COUNTER.getAndIncrement();
intcount(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;
booleancountDownToZero(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 {
...
MapcountOccurrences(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;
Stringcreate()
Returns a unique identifier.
return create("");
StringcreateIdentifier(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());
StringcreateNewTestNamespace(Map environmentProperties)
create New Test Namespace
return environmentProperties.get(KUBERNETES_NAMESPACE_PREFIX_ENV) + "-"
        + subNamespaceCounter.getAndIncrement();
ThreadFactorycreateThreadFactory(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;
};