Which statement is true?

Given the code fragment:

Which statement is true?
A. It never finishes.
B. The action of CyclicBarrier is called five times.
C. It finishes without any exception.
D. Threads in executorService execute for each of the two threads.

Download Printable PDF. VALID exam to help you PASS.

One thought on “Which statement is true?

  1. A

    Note:
    CyclicBarrier – is a synchronizer class that allows a set of threads to wait for each other to reach a common execution point, before continuing to the next execution.

    Therefore a thread that reaches the common point (barrier point) calls await() method until the other threads reach that point.
    And the thread that reaches last executes a Runnable or task if provided by the CiclicBarrier class when it is constructed at its 2nd parameter in addition to the number of threads that should await each other.

    So, here, 2 threads at a time wait each other. 5 numbers (0-4) are generated and 5 threads are dispatched accordingly. But the 5th one waits forever to come another thread on the barrier point.

    2
    1

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.