Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

Implementing FcFs queue with J2SE 5.0

Thread view: 
Veikka - 30 Dec 2005 17:48 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?

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!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.