Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Question: 1 / 50

To reset the count of CountDownLatch, which class can be used instead?

Semaphore

CyclicBarrier

The correct class to use instead of CountDownLatch to reset the count is CyclicBarrier. While ReentrantLock could also be used in certain cases, it is primarily used for providing mutual exclusion between threads. Semaphore and CopyOnWriteArrayList, while they could potentially be used to reset a count, are more commonly used for other purposes such as limiting access to a shared resource and providing thread-safe access to a list, respectively. Thus, B is the most appropriate answer as CyclicBarrier is specifically designed for synchronizing a group of threads and resetting the count as needed.

CopyOnWriteArrayList

ReentrantLock

Next

Report this question