7
What is the output of the following program?
class Main {
public static void main(String[] args) throws Exception {
java.util.concurrent.atomic.AtomicInteger c = new java.util.concurrent.atomic.AtomicInteger();
Thread[] ts = new Thread[4];
for (int i = 0; i < 4; i++) { ts[i] = new Thread(() -> { for (int k = 0; k < 1000; k++) c.incrementAndGet(); }); ts[i].start(); }
for (Thread t : ts) t.join();
System.out.println(c.get());
}
}Hard