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

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

Want to excel in Java? Test your knowledge with our ultimate quiz based on 'Thinking in Java'. Engage with multiple-choice questions and in-depth explanations. Boost your understanding and prepare for your exam with confidence.

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.


What happens if a thread calls acquire() on a Semaphore and no permits are available?

  1. The thread terminates

  2. The Semaphore's count is reset

  3. The thread proceeds without waiting

  4. The thread is blocked until a permit is available

The correct answer is: The thread is blocked until a permit is available

When a thread calls acquire() on a Semaphore and there are no permits available, the thread is blocked until a permit becomes available. This means that the thread will pause and wait until a permit is released by another thread.