[concurrency-interest] ThreadPoolExecutor with PriorityBlockingQueue throws ClassCastException

Joe Bowbeer jozart at blarg.net
Thu Jun 30 08:23:23 EDT 2005


Is there a reason that you're using executorService.submit rather than executor.execute?

The most direct way to accomplish what you want, I believe, would be to create your own ComparableFutureTasks and "execute" them directly -- as executor.execute operates on your FutureTasks directly, without any rewrapping.


On Thu, Jun 30, 2005 at 3:55am Arne Burmeister <Arne.Burmeister at infopark.de> wrote:
> 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 
> FutureTask
> is queued. But there is no chance to get the wrapped Callable from the 
> FutureTask
> 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 
> Comparable
> Future.
> 
> Is this the recommended way to do so? Or should FutureTask implement 
> Comparable
> 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