Hello,
J2SE 5.0 has a lot's of new classes considering multithreading.
What is the best class to implement queue in FirstComesFirstServed model?
Any sample code arapund?
Cheers!
Tris Orendorff - 30 Dec 2005 18:47 GMT
> J2SE 5.0 has a lot's of new classes considering multithreading.
> What is the best class to implement queue in FirstComesFirstServed model?
J2SE 5.0 has a new Queue class. See
http://java.sun.com/j2se/1.5.0/docs/api/java/util/AbstractQueue.html for
details.

Signature
Sincerely,
Tris Orendorff
[Two antennae meet on a roof, fall in love and get married. The ceremony
wasn't much, but the reception was excellent.]
Rhino - 30 Dec 2005 18:54 GMT
> Hello,
>
> J2SE 5.0 has a lot's of new classes considering multithreading.
> What is the best class to implement queue in FirstComesFirstServed model?
The API refers to these as FIFO (first in first out) queues.
> Any sample code arapund?
>
> Cheers!
Have you looked at the API for the Queue interface? It states several
implementations of Queues: if you look at each of those classes, you'll
probably find one that suits your needs.
Queues are part of the Collections interface, which has been reworked to
accomodate Queues and other new features of J2SE 5.0. The Java Tutorial
"trail" (chapter) about Collections has also been updated to reflect Queues.
You can find the updated trail here:
http://java.sun.com/docs/books/tutorial/collections/. There is a bit of
sample code for working with a LinkedList implementation of a Queue in the
Queue interface topic on this page:
http://java.sun.com/docs/books/tutorial/collections/interfaces/queue.html.
However, you should probably read the other pages in that trail that refer
to Queues, not just jump to this page and read it out of context.
Rhino
Veikka - 30 Dec 2005 20:29 GMT
I found a following snippet in Web but it gives warnings.
This should the PriorityQueue I need but there is something wrong....
PriorityQueue <Priority> priorityQueue = new PriorityQueue(10,
new Comparator<Priority>()
{
public int compare(Priority a, Priority b)
{
System.out.println("Comparing Populations");
int populationA = a.getPopulation();
int populationB = b.getPopulation();
if (populationB > populationA)
return 1;
else if (populationB < populationA)
return -1;
else
return 0;
}
}
);
}
> Hello,
>
[quoted text clipped - 4 lines]
>
> Cheers!
Rhino - 30 Dec 2005 21:27 GMT
It's pretty hard for us to diagnose warnings when you haven't told us what
they are. In any case, it would probably be better for you to start a new
thread for this problem and to make the title reflect the new problem, e.g.
Compiler warnings from PriorityQueue.
Rhino
>I found a following snippet in Web but it gives warnings.
> This should the PriorityQueue I need but there is something wrong....
[quoted text clipped - 26 lines]
>>
>> Cheers!