[concurrency-interest] LIFO ThreadPoolExecutor

Andrew Wason rectalogic@yahoo.com
Fri, 29 Oct 2004 19:20:46 -0700 (PDT)


I want to use a single thread ThreadPoolExecutor that
internally uses a LIFO - basically what I would get
from Executors.newSingleThreadExecutor() but using a
LIFO.

I'm queuing up thumbnail decoding tasks as the user
scrolls through a list of thumbnails - so I want the
most recently exposed thumbnail to be the first to be
decoded.

I don't see a BlockingQueue<E> LIFO implementation
that I can use with ThreadPoolExecutor, so what would
be the simplest way to do what I need?

I could use a PriorityBlockingQueue<E> and always add
new tasks as the 'least' element so they are at the
head. Or I could use LinkedBlockingQueue<E> and every
time I add a task, first drainTo(), add the new task,
then addAll() the other tasks back.

I could subclass LinkedBlockingQueue<E> and override
various methods to reimplement it as a LIFO (if
LinkedBlockingQueue<E>.insert() was not private this
would be simple). I'm afraid this approach will be
brittle as the JDK implementation changes underneath
me.

Does anyone have any suggestions as to the best
approach?

Thanks,
Andrew


		
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail