public class CountingSemaphore
extends java.lang.Object
Constructor and Description |
---|
CountingSemaphore(int permits)
Construct a new semaphpore with the specified number of
permits . |
Modifier and Type | Method and Description |
---|---|
void |
acquire()
Acquire the semaphore, blocking if needed until a permit is available.
|
void |
release()
Release the semaphore which was acquired by the current thread using
CountingSemaphore.acquire or CountingSemaphore.tryAcquire . |
boolean |
tryAcquire(int timeout)
Return
true if the semaphore was acquired without blocking for longer than timeout milliseconds, otherwise false (in which case the semaphore was not acquired). |
public CountingSemaphore(int permits)
Construct a new semaphpore with the specified number of permits
.
permits
- Number of permits.public void acquire()
Acquire the semaphore, blocking if needed until a permit is available.
public void release()
Release the semaphore which was acquired by the current thread using CountingSemaphore.acquire
or CountingSemaphore.tryAcquire
.
public boolean tryAcquire(int timeout)
Return true
if the semaphore was acquired without blocking for longer than timeout
milliseconds, otherwise false
(in which case the semaphore was not acquired).
timeout
- Timeout in milliseconds.true
if the semaphore was acquired without blocking for longer than timeout
milliseconds, otherwise false
(in which case the semaphore was not acquired).