Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is a "bounded" queue ?

 
Graeme Byers
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 21197
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic