Implementing FcFs queue with J2SE 5.0

V

Veikka

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!
 
R

Rhino

Veikka said:
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
 
V

Veikka

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;
}
}
);
}
 
R

Rhino

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top