Controle de Filas

2 respostas
S

Salve javarianos,

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

valeus
Luiz

2 Respostas

T

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
S

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

Criado 21 de junho de 2005
Ultima resposta 21 de jun. de 2005
Respostas 2
Participantes 2