threadExamples
Class Queue<V>

java.lang.Object
  extended by threadExamples.Queue<V>
Type Parameters:
V - The type of object that may be put into this Queue.

public class Queue<V>
extends java.lang.Object

A synchronized queue. Objects can be put in the queue and retrieved from it by separate Threads; a request to get something from this Queue will wait (block) until there is something to get.

Version:
Mar 14, 2007
Author:
Dave Matuszek

Constructor Summary
Queue()
           
 
Method Summary
 V get()
          Returns an Object from this Queue, waiting indefinitely if necessary for something to be put in this Queue.
 V get(int limit)
          Returns an Object from this Queue, waiting up to limit milliseconds, if necessary, for something to be put into this Queue.
 void put(V obj)
          Adds an object to this Queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Queue

public Queue()
Method Detail

put

public void put(V obj)
Adds an object to this Queue.

Parameters:
obj - The object to be added.

get

public V get()
Returns an Object from this Queue, waiting indefinitely if necessary for something to be put in this Queue.

Returns:
The Object removed from this Queue.

get

public V get(int limit)
Returns an Object from this Queue, waiting up to limit milliseconds, if necessary, for something to be put into this Queue. If nothing is put into this Queue within the limit, null is returned.

Parameters:
limit - The number of milliseconds to wait.
Returns:
The Object removed from this Queue (or null, if the time limit is exceeded).