[concurrency-interest] Class striped/ordered Thread Pool
viktor.klang at gmail.com
Wed May 16 04:43:30 EDT 2012
On Wed, May 16, 2012 at 10:16 AM, Dr Heinz M. Kabutz <
heinz at javaspecialists.eu> wrote:
> I've spent yesterday and part of today looking at various approaches to
> solve this problem.
> 1. My idea of a striped queue would not work, because tasks are not always
> enqueued before they are handed off to workers.
Ah, the Curse of Order!
> 2. I've got a nice solution utilizing the SerialExecutor approach,
> however, as Joe mentioned, shutdown is particularly challenging. I'm still
> trying to solve that, but it is not easy.
Executor has no shutdown ;-)
> 3. Another challenge, also mentioned already in this thread, is that we
> need to carefully manage the map so that we do not get a memory leak. The
> solution I'm trying now is to delete the SerialExecutor from the map
> whenever it is empty. This might create a lot of objects, but at least we
> don't have to worry about a memory leak.
If you have the SerialExecutor extend CLQ and use a @volatile int/boolean
to keep track of "is scheduled" or not then it's essentially only 2
allocations to create the SerialExecutor:
1 for the head-node in the CLQ and one for the SerialExecutor itself, so it
shouldn't be that bad.
However, the performance will of course vary depending on how it's used.
> Dr Heinz M. Kabutz (PhD CompSci)
> Author of "The Java(tm) Specialists' Newsletter"
> Sun Java Champion
> IEEE Certified Software Development Professionalhttp://www.javaspecialists.eu
> Tel: +30 69 75 595 262
> Skype: kabutz
> On 5/13/12 4:54 AM, Joe Bowbeer wrote:
> On Fri, May 11, 2012 at 12:22 PM, Andrew Trumper wrote:
>> BoundedExecutor is a simple wrapper that limits the number of
>> concurrently running tasks to some number. It doesn't allocate any threads
>> itself (unless you want it to) but uses the "mThreadCache". It's great
>> because it means your whole application can use one thread cache but you
>> can create little thread pools all over the place and not worry about
>> having a bunch of idle threads hangin' around. We use this all the time in
>> our product.
>> (Note, that Joe Bowbeer has mentioned a class called SerialExecutor that
>> seems to do the same thing. ?)
>> BoundedExecutor is part of the nuggu library, BSD license:
>> It would be really great to improve this class and put it in a library
>> someone's actually heard of :-P.
>> (In our product we sometimes use a second BoundedExecutor around the
>> thread cache to limit the concurrency to the number of cores/processors.)
> The SerialExecutor that I referred to is in the Executor javadoc.
> Here is a link to one of the times that a similar problem was discussed
> previously on c-i:
> This post refers to both SerialExecutor and a (different)
> There are several different SerialExecutor and BoundedExecutor
> implementations floating around. In one way, this validates the usefulness
> of the simple Executor interface! In real world applications, I wonder if
> a single BoundedExecutor implementation would be useful. Shutdown is one
> of the missing pieces in these sample implementations -- and this is
> especially difficult to manage when there are multiple, delegating
> executors. I expect that different trade-offs would be chosen in different
> situations, in which case it may be hard to provide a general solution.
> Concurrency-interest mailing listConcurrency-interest at cs.oswego.eduhttp://cs.oswego.edu/mailman/listinfo/concurrency-interest
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
Akka Tech Lead
Typesafe <http://www.typesafe.com/> - The software stack for applications
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest