ThreadPool: only 1 ?

  • Thread starter Thread starter Serge
  • Start date Start date
S

Serge

hi,

the framework has the ThreadPool class. Very handy.
But as far as I can see this is a singleton (only 1 instance).


Does anybody know a way how to have multiple ThreadPools inside a single
application ?

Regards,

Serge
 
I have 2 different kind of tasks.

1, delivery system
2, scripting system

these have to run independantly from each other.
Scripts usually take a short time to process, the delivery long. So I don't
want to have the delivery processes hangs up the script processes.

So I wanted to have 2 threadpools running next to each other.
 
What would a second threadpool do that the first would not? Each thread in
the pool can already run and block independently of the other threads.
Adding a second threadpool would add more available threads but unless you
needed to manage them yourself to add special capabilities it would not
significantly change anything. You might even find that it slows things down
to add more threads as it increases the amount of context switching.
 
Dave said:
What would a second threadpool do that the first would not?

It would block different threads. You could have two pools, one with
long-running tasks and one with short-running tasks. If you only add
the right type of task to each pool, you don't get long-running tasks
blocking short-running tasks, which is what you get with a single pool.
You often only want short-running tasks blocking each other and long-
running tasks blocking each other - that way you end up with a much
shorter latency for short-running tasks than long-running tasks.

I agree with the OP - the current ThreadPool is unfortunately limiting
:(
 
Go for Custome ThreadPools instead of .NET ThreadPool class, There is
implementation by Mike Woodring (Develop mentor) hosted @ his web
site.
 
It would block different threads. You could have two pools, one with
long-running tasks and one with short-running tasks. If you only add
the right type of task to each pool, you don't get long-running tasks
blocking short-running tasks, which is what you get with a single pool.
You often only want short-running tasks blocking each other and long-
running tasks blocking each other - that way you end up with a much
shorter latency for short-running tasks than long-running tasks.

I agree with the OP - the current ThreadPool is unfortunately limiting
:(

I never stated otherwise...in fact, in other posts I've advocated custom
thread pools. I just wanted to make sure the OP knew enough to ensure that a
second threadpool would actually be of benefit. Many people mistakenly
believe that they need a large number of threads when it is common that what
they really need is a better understanding of their requirements.
 
Back
Top