[concurrency-interest] ThreadPoolExecutor with PriorityBlockingQueue throws ClassCastException

Arne Burmeister Arne.Burmeister at infopark.de
Thu Jun 30 06:28:55 EDT 2005

I got in trouble using a ThreadPoolExecutor with a PriorityBlockingQueue.
This seems not to work due to the FutureTask is wrapped around the Callable
passed to submit(), invokeAll() or invokeAny(). The FutureTask is queued but
it is not Comparable. So a ClassCastException is thrown.

Ok, i tried a Comparator set to the PriorityBlockingQueue, seeing the 
is queued. But there is no chance to get the wrapped Callable from the 
to use its Comparable interface. This seems to be a general problem of 
the Java 1.5
implementation. So if i do not have a great misunderstanding of using 
the framework
this is a bug or lack of functionality in the implementation.

Having a look at the JSR166 implementation CVS and also the backport
(Thanks Dawid!) i see at AbstractExecutorService a new factory method
newTaskFor() to create the Future so i may override by one creating a 

Is this the recommended way to do so? Or should FutureTask implement 
delegating to the wrapped task? Or should FutureTask offer the wrapped 
task and i use
a Comparator for the queue?

Thanks in advance,
  Arne Burmeister

More information about the Concurrency-interest mailing list