What is a ThreadPool ? And is it more effective than using several separate Threads ?
What is a ThreadPool ? And is it more effective than using several separate Threads ?
A ThreadPool is a managed collection of threads that runs tasks in parallel from a queue. New tasks are executed on existing threads as those threads become idle. Using a ThreadPool is more effective than creating several separate threads for the following reasons:
Creating threads is expensive, so you should create a ThreadPool only once as your app initializes. Reusing threads in a pool is more efficient than creating and destroying threads for each task.
Threads are not free - they take up memory. Each thread costs a minimum of 64k of memory. This adds up quickly across the many threads in an app. A ThreadPool allows you to limit the number of threads to the minimum needed for your workload.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.