Performance issues
Despite being simple and efficient, our SimpleWebServer application works in a single-threaded model; that is, it always serves one request at a time, failing to increase its performance. If there are 10 simultaneous requests, for example, our SimpleWebServer application will respond to them one by one sequentially.
This, in a real production environment, makes the adoption of a solution such as this unfeasible. But how can we improve the performance of a web server? One of the main solutions for this is to parallelize the processing of requests.
Java's Threads API can give us a remarkably interesting set of parallelism features. Let us imagine that, when accepting a connection, SimpleWebServer delegates its processing to a thread, as in the following diagram:

Figure 3.8: SimpleWebServer threads
Each new thread receives the communication socket, handles the request, and generates a response. In our context, it needs to invoke the handleRequest method. The functioning...