java.util.concurrent · java.base · since Java 1.5
Semaphore
public class Semaphore implements SerializableA permit counter bounding concurrent access: acquire/release around any scarce resource. With virtual threads, the replacement for pool-size-as-limit.
Key methods
Semaphore(int permits, boolean fair) | Fairness prevents starvation at some throughput cost. |
void acquire() / void release() | Take and return a permit (release in finally!). |
boolean tryAcquire(long timeout, TimeUnit) | Bounded wait — the load-shedding form. |