Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

newbie: question on queue  RSS feed

 
pascal gehl
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm fairly new to concurrent programming in java.
I have a use case where a blocking queue seems the perfect answer to my problem.
I only have one problem, from what I read in the jdk javadoc all queue seem to be FIFO, but in my use case it's more complex than that, I need some kind of complex comparator to get the job out the queue. The first in might not be the first out, there are priorities.

Do you know if there is a queue implementation where I can inject a comparator like instance managing the order of jobs?

thanks
PS: if there is really easy answer for this, I apologize in advance.
 
Henry Wong
author
Sheriff
Posts: 22818
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at...

http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/PriorityBlockingQueue.html

It supports both using a Comparator, or having Comparable elements.

Henry
 
pascal gehl
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
great thanks !!!

then it was an easy answer I don't know how I missed this class.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!