Re: SingleThreadExecutor and PriorityBlockingQueue
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
---910079544-468510205-1241436172=:20568
Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8BIT
On Mon, 4 May 2009, mbruun wrote:
On May 1, 5:44?pm, coffeymex <coffey...@gmail.com> wrote:
See the constructor to ThreadPoolExecutor-- as the last parameter, you
can specify the flavour of queue.
Thanks for your reply, Neil.
It true that you can specify the queue as the last parameter to
ThreadPoolExecutor but in this case it does not solve the problem. The
sample code below compiles without errors but when run the
PriorityBlockingQueue will not work because the actual elements inserted
into the queue are of type java.util.concurrent.FutureTask which does
not implement Comparable.
The constructor for PriorityBlockingQueue also has a last parameter which
lets you specify a Comparator which defines the order; that means the
non-comparability of FutureTask doesn't matter. However, it's not obvious
how you'd write a Comparator<FutureTask> which was any use without having
to subclass FutureTask anyway - you can't get at the underlying Runnable
of a FutureTask.
I guess that I could extend the ThreadPoolExecutor and overwrite the
relevant methods to create comparable future tasks. I does not seem
trivial though. So I'm still wondering why Brian Goetz in "Java
Concurrency in Practice" says it can be done (and thinks it's so trivial
that he does not need to mention how).
Maybe his lack of explanation doesn't mean it's trivial, but that it's too
complicated to go into!
tom
--
Everything looks kind of OK
---910079544-468510205-1241436172=:20568--