Question: How many times does the following application print W at runtime? A. 0 B. 10 C. 12 D. The code does not compile. E. The

How many times does the following application print W at runtime? 

package crew; import java.util.concurrent.*; import java.util.stream.*; public class Boat { private void

A. 0

B. 10

C. 12

D. The code does not compile.

E. The output cannot be determined ahead of time.

F. None of the above.

package crew; import java.util.concurrent.*; import java.util.stream.*; public class Boat { private void waitTillFinished (Cyclic Barrier c) { try { c.await (); System.out.print("W"); } catch (Exception e) {} } public void row (Executor Service s) { var cb = new CyclicBarrier (5); IntStream.iterate(1, i-> +1) .limit (12) .forEach(i -> s.submit(()-> waitTillFinished (cb))); } public static void main(String[] oars) { Executor Service service = null; try { service = Executors.newCachedThreadPool(); new Boat ().row (service); } finally { service. isShutdown(); } } }

Step by Step Solution

3.41 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The provided image contains Java code with the purpose of demonstrating concurrency using CyclicBarr... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Oracle Questions!