O'Reilly logo

Java 7 Concurrency Cookbook by Javier Fernández González

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

Creating a thread executor

The first step to work with the Executor framework is to create an object of the ThreadPoolExecutor class. You can use the four constructors provided by that class or use a factory class named Executors that creates ThreadPoolExecutor. Once you have an executor, you can send Runnable or Callable objects to be executed.

In this recipe, you will learn how these two operations implement an example that will simulate a web server processing requests from various clients.

Getting ready

You should read the Creating and running a thread recipe in Chapter 1 to learn the basic mechanism of thread creation in Java. You can compare both mechanisms and select the best one depending on the problem.

The example of this recipe has been ...

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