ISemaphore is a backed-up distributed alternative to the {@link java.util.concurrent.Semaphore}.
ISemaphore is a cluster-wide counting semaphore. Conceptually, it maintains a set of permits. Each {@link #acquire()} blocks if necessary untila permit is available, and then takes it. Each {@link #release()} adds a permit,potentially releasing a blocking acquirer. However, no actual permit objects are used; the semaphore just keeps a count of the number available and acts accordingly.
The Hazelcast distributed semaphore implementation guarantees that threads invoking any of the {@link #acquire() acquire} methods are selectedto obtain permits in the order in which their invocation of those methods was processed(first-in-first-out; FIFO). Note that FIFO ordering necessarily applies to specific internal points of execution within the cluster. So, it is possible for one member to invoke {@code acquire} before another, but reachthe ordering point after the other, and similarly upon return from the method.
This class also provides convenience methods to {@link #acquire(int) acquire} and {@link #release(int) release} multiplepermits at a time. Beware of the increased risk of indefinite postponement when using the multiple acquire. If a single permit is released to a semaphore that is currently blocking, a thread waiting for one permit will acquire it before a thread waiting for multiple permits regardless of the call order.
- Correct usage of a semaphore is established by programming convention in the application.