|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Semaphore
A counting semaphore component maintains a set of permits. Each acquire() blocks if necessary until a permit is available, and then takes it. Each release adds a permit. A semaphore initialized to 1 can serve as a mutual exclusion lock.
Different implementations of this interface may provide different ordering guarantees (or lack thereof) surrounding which threads will be resumed upon a signal.
Note: Inspired by Doug Lea's Semaphore
class.
Field Summary | |
---|---|
static String |
ITF_NAME
The default name of the Semaphore interface. |
Method Summary | |
---|---|
void |
acquire()
Waits until a permit is available, and take one |
boolean |
attempt(long msecs)
Waits at most msecs millisconds for a permit. |
long |
permits()
Returns the current number of available permits. |
void |
release()
Release a permit |
void |
release(long n)
Releases N permits. |
Field Detail |
---|
static final String ITF_NAME
Semaphore
interface.
Method Detail |
---|
void acquire() throws InterruptedException
InterruptedException
- if the thread is interrupted while trying to
acquire the permit.boolean attempt(long msecs) throws InterruptedException
msecs
- the number of milleseconds to wait. An argument less than or
equal to zero means not to wait at all. However, this may still
require access to a synchronization lock, which can impose
unbounded delay if there is a lot of contention among threads.
InterruptedException
- if the thread is interrupted while waiting for
the permit.long permits()
void release()
void release(long n) throws IllegalArgumentException
n
- the number of permits to be released.
IllegalArgumentException
- if n is negative.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |