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

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

Prepare for your Java exam with our ultimate quiz based on 'Thinking in Java'. Engage with expertly crafted questions that enhance your learning process. Perfect for Java enthusiasts looking to solidify their knowledge!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


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

  1. Semaphore

  2. CyclicBarrier

  3. CopyOnWriteArrayList

  4. ReentrantLock

The correct answer is: 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.