What is the result of executing the following application? (Choose all that apply.)
import java.util.concurrent.*; import java.util.stream.*; public class Main { public static void main(String[] args) { ExecutorService service = Executors.newScheduledThreadPool(10); DoubleStream.of(3.14159,2.71828) // b1 .forEach(c -> service.submit( // b2 () -> System.out.println(10*c))); // b3 service.execute(() -> System.out.println("Printed")); // b4 } // w ww. j a v a 2s . co m }
F, H.
The application compiles and does not throw an exception, so B, C, D, E, and G are incorrect.
Even though the stream is processed in sequential order, the tasks are submitted to a thread executor, which may complete the tasks in any order.
Therefore, the output cannot be determined ahead of time and F is correct, making A incorrect.
Finally, the thread executor is never shut down; therefore the code will run but it will never terminate, making H also correct.