views:

171

answers:

2

Hello

I'm not able to understand the difference between Thread vs ThreadPool. Consider i've to manipulate 50,000 records using threads.

In case of threads i need to either predefine no of threads or no of records per threads. Either of them has to be constant.

In case of threadpool we dont need to set any of them theoretically. But practically we need to assign the number of records per thread, because the no of threads may grow extremely large if the input no of records is huge.

Any insights on this?

+1  A: 

There is a huge cost in creating and destroying threads. A thread pool takes away this problem by maintaining open threads for you. When a thread in a pool is done with its work, the thread is returned to the pool instead of being destroyed. Then when you have to do more work, the already open thread is taken from the pool. This is much more efficient.

Tom Cabanski
+1  A: 

Here is a complete treatment on Threads and ThreadPools that will answer your question. includes when to use one vs the other.

http://www.yoda.arachsys.com/csharp/threads/

Romain Hippeau