11
Loading subject content…
Loading subject content…
Loading practice questions…
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());
}
}What is the output of the following program?
public class Main {
public static void main(String[] args) throws Exception {
var pool = java.util.concurrent.Executors.newSingleThreadExecutor();
var f = pool.submit(() -> 6 * 7);
System.out.println(f.get());
pool.shutdown();
}
}