[concurrency-interest] LIFO ThreadPoolExecutor

Paulo Levi i30817 at gmail.com
Tue Apr 28 15:43:36 EDT 2009


I'm doing requests to a web service for thumbnails over a
threadpoolexecutor, configured like this:
http://www.kimchy.org/juc-executorservice-gotcha/

As I'm using a web service I'd like to configure the Linked blocking queue
the executors use to be able to be LIFO (according to the factory method),
so that the relevant requests are processed first.

I have these static factory methods :
    /**
     * A pool with exactly nThreads that don't timeout
     * @param nThreads > 0
     * @return
     */
    public static ChainExecutorService newFixedThreadPool(int nThreads)
(using linkedBlockingQueue)

    /**
     * A pool that has no maximum number of threads
     * and will kill the threads after a timeout after the last task
     * @param secondsTimeOut > 0
     * @return
     */
    public static ChainExecutorService newCachedThreadPool(long
secondsTimeout)
(using SynchronousQueue)

    /**
     * A pool that has a maximum number of threads
     * and will kill the threads after a timeout after the last task
     * @param maximumNThreads > 0
     * @param secondsTimeOut > 0
     * @return
     */
    public static ChainExecutorService newScalingThreadPool(int
maximumNThreads, long secondsTimeOut)
(using a equivalent class to ScalingQueue from the blog above - extends
LinkedBlockingQueue)
    /**
     * A pool that has a minimum number of threads, a maximum number of
threads
     * and will kill maximumNThreads - minimumNThreads after a timeout after
the last task
     * @param minimumNThreads >= 0
     * @param maximumNThreads > 0
     * @param secondsTimeOut > 0
     * @return
     */
        public static ChainExecutorService newScalingThreadPool(int
minimumNThreads, int maximumNThreads, long secondsTimeOut)
(using a equivalent class to ScalingQueue from the blog above - extends
LinkedBlockingQueue)

I'm asking the way to modify LinkedBlockingQueue and SynchronousQueue so
that i can implement LIFO for the ThreadPoolExecutor.

I know this is a complex question - but i'm really raw at implementing data
structures like this, and i fear screwing it up.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090428/e9ea1161/attachment.html>


More information about the Concurrency-interest mailing list