public class Queue
extends java.lang.Object
get()
will block
until another thread has put an object in the queue. Similarly, the method put()
blocks if the queue is
full. However, the put()
method will not block if the queue has no maximum size. To create a new queue, the
maximum size must be specified. This is an integer, and if it has a value of zero or less than zero, it is assumed that
the queue has no maximum size.
The Queue class is thread safe. This means that your methods for calling the get()
and put()
method need not synchronize on the queue object.Constructor and Description |
---|
Queue(int maximumSize)
Creates a new queue of the specified size.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
get()
Gets an object from queue.
|
java.lang.Object |
get(long timeout)
Gets an object from queue, within a given timeout period.
|
int |
getMaxSize()
Returns the maximum queue size
|
java.lang.Object |
nonBlockingGet()
This method returns either the front object from the queue, or null
if the queue is empty.
|
void |
nonBlockingPut(java.lang.Object object)
Put a object in the queue, non blocking, the queue could grow over it's max size.
|
protected void |
notifyGetWait(int duration)
Extension point for any sub-classes that want to be informed about
incured during 'get' operations.
|
protected void |
notifyPutWait(int duration)
Extension point for any sub-classes that want to be informed about
incured during 'put' operations.
|
void |
put(java.lang.Object object)
Put an object into queue.
|
int |
size()
Returns the number of items currently in the queue.
|
public Queue(int maximumSize)
maximumSize
- The maximum size for the queue; if this is less than or equal to zero, the queue does not
have a maximum size.public java.lang.Object nonBlockingGet()
public void nonBlockingPut(java.lang.Object object)
object
- public java.lang.Object get()
public java.lang.Object get(long timeout)
timeout
- the maximum time to wait in milliseconds.public void put(java.lang.Object object)
object
- The object to put in the queue.public int size()
public int getMaxSize()
protected void notifyGetWait(int duration)
duration
- Duration of the wait period before 'get' finds an itemprotected void notifyPutWait(int duration)
duration
- Duration of the wait period before 'put' finds a free spot