Supun Wijerathne Supun Wijerathne - 1 month ago 20
Java Question

Are Java Semaphores strong semaphores by default?

I know we can implement a Strong Semaphore by Semaphore(int permits,
boolean fair)
. Apart of that what would happen if we just make one with Semaphore(int permits)?

Would it be a strong semaphore by default? I have searched number of sources and none of them had the answer for this.

Answer

You have not stated clearly what you mean by a "strong" semaphore. However, since you state that you can implement one using Semaphore(int permits, boolean fair), I'm assume you mean a "fair" semaphore.

Either way, Semaphore(permits) is equivalent to Semaphore(permits, false), as implied by the javadocs.

You can see this in the source code.