[concurrency-interest] ThreadPoolExecutor with PriorityBlockingQueue throws ClassCastException

Tim Peierls tim at peierls.net
Thu Jun 30 13:22:25 EDT 2005


Arne Burmeister wrote:
>> ...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?

Joe Bowbeer wrote:
> 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.

Two cases where you can't use the "direct" approach:

1. ExecutorCompletionService.submit
2. ExecutorService.invokeAll/invokeAny

In case #1, since the underlying Runnable that is constructed by the submit
method is hardwired and not overridable, there is not much you can do. I
hadn't noticed this until your email provoked me to look.

[Doug, is it too late to fix this for Mustang?]

In case #2, under Mustang, you will be able to use the newTaskFor approach. 
Pre-Mustang, you can override the submit(Callable) method of 
ThreadPoolExecutor.

--tim




More information about the Concurrency-interest mailing list