public class Semaphore
extends java.lang.Object
Modifier and Type | Field | Description |
---|---|---|
protected int |
capacity |
Semaphore capacity, defined when the semaphore is created.
|
Constructor | Description |
---|---|
Semaphore(int capacity) |
Creates a new semaphore with the given capacity.
|
Modifier and Type | Method | Description |
---|---|---|
void |
acquire() |
Locks on the semaphore object with no timeout
|
void |
acquire(double timeout) |
Locks on the semaphore object until the provided timeout expires
|
protected void |
finalize() |
Deletes this semaphore when the GC reclaims it
|
int |
getCapacity() |
Returns the semaphore capacity
|
static void |
nativeInit() |
Class initializer, to initialize various JNI stuff
|
void |
release() |
Releases the semaphore object
|
boolean |
wouldBlock() |
returns a boolean indicating it this semaphore would block at this very specific time
Note that the returned value may be wrong right after the
function call, when you try to use it...
|
protected final int capacity
public Semaphore(int capacity)
public void acquire(double timeout) throws TimeoutException
timeout
- the duration of the lockTimeoutException
- if the timeout expired before
the semaphore could be acquired.public void acquire()
public void release()
public boolean wouldBlock()
public int getCapacity()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public static void nativeInit()