December 2015
Intermediate to advanced
292 pages
6h 16m
English
We introduced the HTTPServer class in Chapter 4, Client/Server Development. When the HTTP Server receives a request, by default, it uses the thread that was created when the start method is called. However, it is possible to use a different thread. The setExecutor method specifies how these requests are assigned to threads.
The argument of this method is an Executor object. We can use any of several implementations for this argument. In the following sequence, a cached thread pool is used:
server.setExecutor(Executors.newCachedThreadPool());
To control the number of threads that are used by the server, we can use a fixed thread pool of size 5, as shown here:
server.setExecutor(Executors.newFixedThreadPool(5));
This method ...
Read now
Unlock full access