GAjanan Udas
GAjanan Udas

Reputation: 1

Which is more expensive? Keeping threads running in Thread Pool or Creating new Thread?

Creating new thread is considered as expensive task. But in thread Pull we create many threads and keep them running even no task is available to perform. why it is not more expensive to keep idle threads running rather than creating threads as and when needed? Though Threads are idle they must be occupying the resources like fixed memory, OS schedule etc. Then how thread pool is more optimized way?

Upvotes: 0

Views: 477

Answers (1)

David Schwartz
David Schwartz

Reputation: 182827

Because creating and destroying threads is expensive. If your threads are idle, then you don't have a lot of work to do. You don't need to work efficiently when you don't have a lot of work to do, you need to work efficiently when you do have a lot of work to do.

Upvotes: 1

Related Questions