|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectthread.BoundedBuffer
public class BoundedBuffer
A bounded buffer has some capacity to store objects.
With the method put
objects are placed into
the buffer, and with the get
objects are taken
from the buffer.
put
blocks if there is no space to
place a object into the buffer.
get
blocks if there are no objects in the buffer.
The objects are put to and get from the buffer in FIFO order.
see Channel
see MemoryChannel
see SyncChannel
see Stack
Field Summary | |
---|---|
private java.lang.Object[] |
buffer
The buffer storage of objects. |
private Semaphore |
empty
A semaphore to indicate an empty buffer. |
private int |
front
The position of the first filled cell. |
private Semaphore |
full
A semaphore to indicate a full buffer. |
private java.lang.Object |
gt
|
private java.lang.Object |
pt
|
private int |
rear
The position of the first empty cell. |
private int |
size
The size of the buffer. |
Constructor Summary | |
---|---|
BoundedBuffer(int init)
Constructs a BoundedBuffer with a desired size. |
Method Summary | |
---|---|
boolean |
empty()
Tests if the BoundedBuffer is empty. |
java.lang.Object |
get()
Get an object from the BoundedBuffer |
void |
put(java.lang.Object v)
Add an object to the BoundedBuffer |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.lang.Object[] buffer
private int size
private int front
private int rear
private Semaphore empty
private Semaphore full
private java.lang.Object pt
private java.lang.Object gt
Constructor Detail |
---|
public BoundedBuffer(int init)
init
- the size of the buffer.Method Detail |
---|
public boolean empty()
public void put(java.lang.Object v) throws java.lang.InterruptedException
v
- object to be added to the buffer.
java.lang.InterruptedException
public java.lang.Object get() throws java.lang.InterruptedException
java.lang.InterruptedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |