Delivering Measurable Online Success

Need of Thread Pools:

July 6, 2009 – 3:53 am

There are many real world programming models where we must use threads. They are used when we have to do a lot of simultaneous processing, whether it is a web server processing a large number of user requests or a desktop application processing a lot of URLs to fetch and process their content.

In any of the above scenarios, we generally need a thread-per-request model, but the biggest disadvantage of this approach is the overhead of creating and destroying threads and active threads consume system resources. This approach will make a situation where the application would consume more time and system resources in creating and destroying thread objects rather than processing actual tasks.

Thread Pools come to rescue from these situations. While working with thread pools we get the following benefits that solve our problems to a large extent:

1. By reusing threads, the overhead of creating and destroying threads is reduced.
2. Small number of threads consume less amount of system resources especially memory, so JVM will not give frequent out of memory errors.
3. Requests are served faster because the delay caused in creating new threads-per-request is negligible.
4. Huge amount of requests can be processed in less amount of time and by consuming less amount of system resources.

Thread pools help us to process more number of tasks in a parallel way and by using the system resources in controlled manner.

Post a Comment

*Please fill correct value in the text box given below.