Java AtomicInteger is using the regular 4 bytes length of int
.
If we run the following code
AtomicInteger i = new AtomicInteger(Integer.MIN_VALUE);
System.out.println(i);
i.decrementAndGet();
System.out.println(i);
We will get
-2147483648
2147483647
Is there a way to set the size of the atomic integer, to make it 20 bits long instead of 32 bits and maintain the atomicity?
for example, the new result will be
-524288
524287
which is -2^19
and 2^19-1