aspose file tools*
The moose likes Beginning Java and the fly likes What is a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is a "bounded" queue ?" Watch "What is a "bounded" queue ?" New topic
Author

What is a "bounded" queue ?

Graeme Byers
Ranch Hand

Joined: Apr 16, 2004
Posts: 127
1. "A bounded queue is a first-in-first-out queue with a fixed capacity"
http://venus.cs.depaul.edu/Java/chap08.html

2. "It is possible for a Queue implementation to restrict the number of elements that it holds; such queues are known as bounded. Some Queue implementations in java.util.concurrent are bounded, but the implementations in java.util are not.
http://java.sun.com/docs/books/tutorial/collections/interfaces/queue.html

3. Well , java.util.PriorityQueue has a constructor PriorityQueue (int initialCapacity) so is it bounded (1) or not (2) ? I am assuming that "restricting size" has something to do with capacity - is that true ?

4. How can I estimate capacity if I know the number of objects a Collection contains ?

5. What happens when a Collection exceeds its capacity - exception , silently give me some more ?

Thank you

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Graeme Byers wrote:3. Well , java.util.PriorityQueue has a constructor PriorityQueue (int initialCapacity) so is it bounded (1) or not (2) ? I am assuming that "restricting size" has something to do with capacity - is that true ?

From its API:
An unbounded priority queue based on a priority heap.

So (2).

4. How can I estimate capacity if I know the number of objects a Collection contains ?

If the class does not have a method for it, you can't.

5. What happens when a Collection exceeds its capacity - exception , silently give me some more ?

If with capacity you mean the capacity like PriorityQueue and ArrayList have, then it will increase the capacity when necessary.

If you mean the capacity of a bounded collection, it depends on the class. Some may block until there is enough space (by removing other elements from another thread), some may throw an exception. Always check the class API.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18855
    
  40

3. Well , java.util.PriorityQueue has a constructor PriorityQueue (int initialCapacity) so is it bounded (1) or not (2) ? I am assuming that "restricting size" has something to do with capacity - is that true ?


No. PriorityQueue is not bounded. Being able to specify the initial capacity is not the same as being able to specify the maximum capacity. A PriortityQueue can grow in an unbounded manner.

4. How can I estimate capacity if I know the number of objects a Collection contains ?




5. What happens when a Collection exceeds its capacity - exception , silently give me some more ?


I beleive most (if not all) of the bounded queues, are blocking queues, so the adding to a queue will wait until there is room.

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: What is a "bounded" queue ?