user1399653
user1399653

Reputation: 193

Multithreading - New Thread vs ThreadPool

I have read in several blogs that we should create our own threads for long running, or blocking tasks and not consume from the thread pool.

My question: if I set setmaxthreads to 250 and I have 25 long running tasks, should I still create my own threads? I still have the remainder threads for other small tasks.

Upvotes: 1

Views: 187

Answers (1)

Andrew Barber
Andrew Barber

Reputation: 40139

If they are long-running tasks, you should not use the ThreadPool at all. You really should not usually tweak the thread pool settings; certainly not to avoid this. Note that the thread pool size is limited for a reason; too many threads running at one time is a bad thing, too.

So, let the ThreadPool do what it's supposed to do, and just create your own thread for your long-running tasks. (assuming you aren't creating dozens or hundreds of these; in which case you have a different problem)

Upvotes: 3

Related Questions