Controle de Filas  XML
Índice dos Fóruns » Java Avançado
Autor Mensagem
Siborges
HelloWorld

Membro desde: 09/05/2005 11:01:38
Mensagens: 13
Localização: Curitiba
Offline

Salve javarianos,

alguem tem algum exemplo ou pode dar uma ajudo na utilização da classe java.util.concurrent.PriorityBlockingQueue ?

valeus
Luiz

O tempo passa, o tempo voa, e a poupança Bamerindus...
[WWW] [MSN]
thingol
Moderador

Membro desde: 29/07/2004 16:10:13
Mensagens: 17543
Offline

javarianos


Ainda bem que não disse "javiados" - era isso que um colega meu de .NET ficava dizendo, só para provocar a gente...

De qualquer maneira, nada que o Google não ache para a gente:

http://www-106.ibm.com/developerworks/java/library/j-tiger06164.html

PriorityBlockingQueue is a queue with an unbound capacity that maintains elements in their logical order through use of the Comparable sort order of the contained elements. Think of it as a possible replacement for TreeSet. For instance, adding the strings One, Two, Three, and Four to the queue will result in Four being the first one taken out. For elements without a natural order, you can provide a Comparator to the constructor. There is one trick with PriorityBlockingQueue, though. The Iterator instance returned from iterator() doesn't necessarily return the elements in priority order. If you must get all the elements in priority order for traversal, get them all through the toArray() method and sort them yourself, like Arrays.sort(pq.toArray())


http://www.javalobby.org/java/forums/t16278.html


Ahh, priorities. Sometimes, one thing is more important than another. Let's face it - feeding your family is more important than buying that Ferrari (I hope), and as such you're kids are eating, and you're driving a 1984 minivan with a broken rear window. The priority blocking queue ensures that items with the highest priority are handed out first. This is a fun analogy. We now get to assume that some WidgerFurmuzzit's are more valuable than others. As such, the higher paying customers get priority in their purchases. If anyone isn't familiar with a standard priority queue, I suggest reading the Javadocs here:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/PriorityQueue.html
Note that the higher a cost, the 'higher' the ranking in a comparison, but in a priority queue, the lower the ranking in a comparison, the sooner it will be returned. See below for an example with our furry furmuzzits.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/PriorityBlockingQueue.html

This message was edited 1 time. Last update was at 21/06/2005 14:46:15

[WWW]
Siborges
HelloWorld

Membro desde: 09/05/2005 11:01:38
Mensagens: 13
Localização: Curitiba
Offline

Salve Thingol
valeu pelo link do javalobby, não tinha visto ele entra as respostas do magavilhoso google. Mas mesmo assim ainda não sei como utilizar, a idéia da classe é legal, aparenta facilitar uma ou outra coisa, só não sei pq o maledito cliente quer tanto que eu a utiliza eheheh..

valeu
Luiz

O tempo passa, o tempo voa, e a poupança Bamerindus...
[WWW] [MSN]
 
Índice dos Fóruns » Java Avançado
Ir para:   
Powered by JForum 2.1.8 © JForum Team