You get it and increase it by two separate actions. You print the first thing that makes your own code non-atomic.
Each AtomicInteger operation is an atom in itself , but you cannot use two in a sequence and consider a combination of an atom - by definition, two operations are not atomic.
To fix this:
@Override
public void run()
{
System.out.println(x.getAndIncrement());
}
, , - . . , , .
printAndIncrement.
AtomicInteger , , , , (, ) ( - ).