Peter Kovac wrote:
Is it possible that AtomicInteger.incrementAndGet or similar methods will run forever?
In theory, I guess it is possible. In practice, I don't see how.
The only way to get an infinite loop, is to have constant CAS failures. And the only way to have constant CAS failures, is for another thread to exist -- another thread which constantly changes the integer. And for the scheduler to have the other thread change the integer in a way that your thread can't do two iterations in a row.