queue : Java Glossary
home Q words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish 2008-03-01 by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
queue
A data structure to hold objects awaiting some sort of service. There are two basic types: FIFO (First In First Out) and LIFO (Last In First Out). LIFO queues are often called stacks. Internally threads waiting for a timeslice of CPU time are stored in a queue. Inside a servlet womb, incoming translations awaiting processing are stored in a queue. Prior to Java 1.5, there was almost no support for queues other than LinkedList. You had to roll your own, which is not difficult. See my own LinkedList implementation.
Queue Classes Learning More
How to Use Links
Books

Queue Classes

With Java 1.5 comes a rich set of classes:
Java Queues classes and interfaces
Class Type Purpose
Queue interface Basic queue interface. Defines the basic methods to add elements to the queue (offer, add), look at the head of the queue (peek, element) or pop the head of the queue off the queue (poll, remove) Queue is derived from Collection so all the Collection methods are also available.
BlockingQueue interface If the queue is empty, blocks the current thread until some other thread adds an element. You can provide a timeout how long you are prepared to wait.
AbstractQueue abstract class Underpinnings for ArrayBlockingQueue, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingQueue, PriorityBlockingQueue, PriorityQueue, SynchronousQueue.
ArrayBlockingQueue class FIFO blocking queue where the elements are stored in an fixed size array. The array buffer is circular, somtimes called a squirrel cage buffer or hamster buffer. When the array fills up it wraps around to the beginning being careful not to overwrite existing elements. If all goes well, the oldest elements are popped off in time to create room for new elements, hot on their heels.
ConcurrentLinkedQueue class Unbounded (can grow arbitrarily large), FIFO, thread-safe queue.
DelayQueue class Unbounded, sorted by delay, so that elements can be eligible to leave the queue once the delay has expired. The oldest expired delay element pops from the queue first.
LinkedBlockingQueue class Optionally bounded, FIFO blocking queue implemented with linked nodes.
LinkedList class Supports List interface, though it is very slow at indexing since it is implemented as linked nodes.
PriorityBlockingQueue class Blocking, sorted queue ordered by natural order Comparable interface or supplied Comparator. Does not permit null elements. Pops the smallest element.
PriorityQueue class Non-blocking, sorted queue ordered by natural order Comparable interface or supplied Comparator. Does not permit null elements. Pops the smallest element.
SynchronousQueue class A dummy queue that can’t even hold one element. Every add to the queue must be matched by an immediate pop before there can be another add. It is for thread to thread handoff.

How to Use

There are many variations, but this should give you the general idea.

Books

book_cover recommend book⇒Java Concurrency in Practice
 paperback
ISBN10:0-321-34960-1
ISBN13:978-0-321-34960-6
publisher:Addison-Wesley
published:2006-05-19
by:Brian Goetz, Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes, Doug Lea
Bloch and Lea especially have very good reputations in concurrent programming. This is the dream team to write such a book. See the companion website with code examples, a sample chapter, errata etc..
Canadian flag amazon.ca. amazon.com. American flag
Canadian flag chapters.indigo.ca . powells.com American flag
French flag amazon.fr. barnesandnoble.com American flag
German flag amazon.de. amazon.co.uk. UK flag

Learning More

Sun’s Javadoc on the Queue interface class : available:
Sun’s Javadoc on java.util.concurrent package : available:

CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.17] Spread the Net
You are visitor number 13,144.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/queue.html J:\mindprod\jgloss\queue.html