Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when a thread pool is exhausted?

In a recent course at school about networking / operating systems I learned about thread pools. Now he basic functionality is pretty straight forward and I understand this.

However, what's not specified in my book is what happens when the thread pool is exhausted? For example you have a pool with 20 threads in it and you have 20 connected clients. Another client tries to connect but there's no threads left in the pool, what happens then? Does the client go in a queue? Does the system make another thread to put in the pool? Something else?

like image 459
user757926 Avatar asked Jun 13 '13 14:06

user757926


People also ask

What happens when thread pool is full in Java?

Once 'max' number of threads are reached, no more will be created, and new tasks will be queued until a thread is available to run them.

What is the purpose of a thread pool?

A thread pool is a collection of worker threads that efficiently execute asynchronous callbacks on behalf of the application. The thread pool is primarily used to reduce the number of application threads and provide management of the worker threads.

What is thread pool starvation?

ThreadPool starvation occurs when the pool has no available threads to process new work items and it often causes applications to respond slowly. Using the provided example ASP.NET Core web app, you can cause ThreadPool starvation intentionally and learn how to diagnose it.


1 Answers

The answer depends highly on your language, your operation system, and your pool implementation.

what happens when the thread pool is exhausted? Another client tries to connect but there's no threads left in the pool, what happens then? Does the client go in a queue?

Typically in a server situation, it depends on the socket settings. Either the socket connection gets queued by the OS or the connection gets refused. This is usually not handled by the thread-pool. In ~unix operation systems, this queue or "backlog" is handled by the listen method.

Does the system make another thread to put in the pool?

This depends on the thread-pool. Some pools are fixed size so no more threads will be added. Other thread-pools are "cached" thread pools so it will reuse a free thread or will create a new one if none are available. Many web servers have max thread settings on their pools so remote users don't thrash the system by starting too many concurrent connections.

like image 66
Gray Avatar answered Oct 03 '22 12:10

Gray