Java java.util.concurrent Semaphore fields, constructors, methods, implement or subclass

Example usage for Java java.util.concurrent Semaphore fields, constructors, methods, implement or subclass

Introduction

In this page you can find the methods, fields and constructors for java.util.concurrent Semaphore.

The text is from its open source code.

Implementation

java.util.concurrent.Semaphore has the following implementations.
Click this link to see all its implementation.

Constructor

Semaphore(int permits, boolean fair)
Creates a Semaphore with the given number of permits and the given fairness setting.
Semaphore(int permits)
Creates a Semaphore with the given number of permits and nonfair fairness setting.

Method

voidacquire()
Acquires a permit from this semaphore, blocking until one is available, or the thread is Thread#interrupt interrupted .
voidacquire(int permits)
Acquires the given number of permits from this semaphore, blocking until all are available, or the thread is Thread#interrupt interrupted .
voidacquireUninterruptibly()
Acquires a permit from this semaphore, blocking until one is available.
voidacquireUninterruptibly(int permits)
Acquires the given number of permits from this semaphore, blocking until all are available.
intavailablePermits()
Returns the current number of permits available in this semaphore.
intdrainPermits()
Acquires and returns all permits that are immediately available, or if negative permits are available, releases them.
intgetQueueLength()
Returns an estimate of the number of threads waiting to acquire.
booleanhasQueuedThreads()
Queries whether any threads are waiting to acquire.
voidrelease()
Releases a permit, returning it to the semaphore.
voidrelease(int permits)
Releases the given number of permits, returning them to the semaphore.
booleantryAcquire(long timeout, TimeUnit unit)
Acquires a permit from this semaphore, if one becomes available within the given waiting time and the current thread has not been Thread#interrupt interrupted .
booleantryAcquire(int permits)
Acquires the given number of permits from this semaphore, only if all are available at the time of invocation.
booleantryAcquire(int permits, long timeout, TimeUnit unit)
Acquires the given number of permits from this semaphore, if all become available within the given waiting time and the current thread has not been Thread#interrupt interrupted .
booleantryAcquire()
Acquires a permit from this semaphore, only if one is available at the time of invocation.