What is the output of the following Java program?
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class Main {
public static void main(String[] args) {
AtomicInteger visits = new AtomicInteger();
try (ExecutorService pool = Executors.newFixedThreadPool(8)) {
for (int i = 0; i < 1000; i++) pool.submit(visits::incrementAndGet);
}
System.out.println(visits.get() + " " + visits.addAndGet(-500) + " " + visits.getAndIncrement() + " " + visits);
}
}
Atomic increments never lose updates. getAndIncrement returns the old value (500) and then adds 1.