Question 1
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class Main {
public static void main(String[] args) {
ExecutorService pool = Executors.newFixedThreadPool(2);
Future<Integer> f = pool.submit(() -> 6 * 7);
System.out.println(f.get());
pool.shutdown();
}
}
- A submit cannot take a lambda
- B Future.get throws the checked InterruptedException and ExecutionException, which main neither catches nor declares Correct
- C Future must be Future<int>
- D shutdown must come first
Correct Answer: Option B
javac: "unreported exception InterruptedException; must be caught or declared to be thrown".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!