[concurrency-interest] Regarding a design suggestion..

David Holmes dcholmes at optusnet.com.au
Thu Mar 15 00:02:17 EDT 2007


Rajesh,

If the queues were directly attached to the pools you wouldn't need the
intermediate threads. You also may not need three pools. Direct insertion
into the queue has some issues when the queue is attached to a pool - it
avoids the normal thread creation logic - but you can work around that to
some extent by either pre-priming the pool, or else turning what appears to
be queue.put() into an Executor.execute.

David Holmes

> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu
> [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Rajesh
> Balamohan
> Sent: Thursday, 15 March 2007 1:02 PM
> To: concurrency-interest at cs.oswego.edu
> Subject: [concurrency-interest] Regarding a design suggestion..
>
>
> Any inputs on this would be of great help Dough.
>
>
>                 ============                 ============
>                 |          |                 |          |
>                 |          |                 |          |
> Insert Item =>  | Inbound  |                 | Outbound |   ===> out
>                 |  Queue   |                 |  Queue   |
>                 |          |                 |          |
>                 |          |                 |          |
>                 ============                 ============
>                     |                            |
>                     |                            |                |
>                     |                            |------------- |
>     1.    A seperate thread does                                  |
>         queue.take() from here                  1.    A seperate
> thread does
>     2. Creates a runnable task and                  queue.take()
> from outbound queue
>     enques to ThreadPoolExecutor (B)           2. Creates a
> runnable task and
>                                                 enques to
> ThreadPoolExecutor (C)
>
>
>
>
> Please let me know if you need more explanation.
>
> 1. There are 2 LinkedBlockingQueue. One for inbound and another
> for outbound
> 2. There are 3 ThreadPoolExecutors available. Letz say A, B, C
> 3. Someone puts a task in "A", which puts an item in InboundQueue.
> 4. A separate thread is blocked on "take()" method of this queue.
> Once it gets an item, it
> creates another "TASK" and puts it in "B" threadpool.
> 5. This task does some work and finally enqueues to "OUTBOUND QUEUE"
> 6. OUTBOUND Queue has a separate thread to dequeue and do some
> processing in "C" threadpool.
>
> Problem:
> ========
> 1. Too many short lived tasks are created.
> 2. Too many context switching happening in system due to #1.
> 3. Do you suggest any better way to implement it. Basic thing is
> the queueing and dequeuing has to happen asynchronously.
>
>
> --
> ~Rajesh.B



More information about the Concurrency-interest mailing list