The ThreadPool class
Thread creation is an expensive operation in terms of both memory and CPU resources. On average, every thread consumes around 1 MB of memory and a few hundred microseconds of CPU time. Application performance is a relative concept, so it will not necessarily improve by creating a large number of threads. Conversely, creating a large number of threads can sometimes decrease application performance drastically. We should always aim to create an optimal number of threads, depending on the target system's CPU load, that is, other programs running on the system. This is because every program gets a time slice by the CPU, which is then distributed among the threads inside the application. If you create too many threads, they ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access