O'Reilly logo

Learning Network Programming with Java by Richard M Reese

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Thread pools

Thread pools are useful when the number of threads that are created need to be limited. Using a pool not only controls how many threads are created, but it can also eliminate the need to create and destroy threads repeatedly, an often expensive operation.

The following figure depicts a thread pool. Requests are assigned to threads in the pool. Some thread pools will create new threads if there are no unused threads available. Others will restrict the number of threads available. This may result in some requests being blocked.

Thread pools

We will demonstrate thread pools using the ThreadPoolExecutor class. This class also provides methods that deliver ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required