Posts

Thread Pools in Java

Image
Thread Pools in Java Background Server Programs such as database and web servers repeatedly execute requests from multiple clients and these are oriented around processing a large number of short tasks. An approach for building a server application would be to create a new thread each time a request arrives and service this new request in the newly created thread. While this approach seems simple to implement, it has significant disadvantages. A server that creates a new thread for every request would spend more time and consume more system resources in creating and destroying threads than processing actual requests. Since active threads consume system resources, a  JVM  creating too many threads at the same time can cause the system to run out of memory. This necessitates the need to limit the number of threads being created. What is ThreadPool in Java? A thread pool reuses previously created threads to execute current tasks and offers a solution to the proble...