title: How do I implement task prioritization using an ExecutorService in Java 5?
body: <p>I am implementing a thread pooling mechanism in which I'd like to execute tasks of varying priorities.  I'd like to have a nice mechanism whereby I can submit a high priority task to the service and have it be scheduled before other tasks.  The priority of the task is an intrinsic property of the task itself (whether I express that task as a <code>Callable</code> or a <code>Runnable</code> is not important to me).</p>
  
  <p>Now, superficially it looks like I could use a <code>PriorityBlockingQueue</code> as the task queue in my <code>ThreadPoolExecutor</code>, but that queue contains <code>Runnable</code> objects, which may or may not be the <code>Runnable</code> tasks I've submitted to it.  Moreover, if I've submitted <code>Callable</code> tasks, it's not clear how this would ever map.</p>
  
  <p>Is there a way to do this?  I'd really rather not roll my own for this, since I'm far more likely to get it wrong that way.</p>
  
  <p>(An aside; yes, I'm aware of the possibility of starvation for lower-priority jobs in something like this.  Extra points (?!) for solutions that have a reasonable guarantee of fairness)</p>