The thread-per-request approach

In Chapter 1, Getting Started with Network Programming, we illustrated a simple multithreaded echo server. This approach is reintroduced here to provide a foundation for the use of threads in the remainder of the chapter.

The thread-per-request server

In this example, the server will accept requests for prices when given the name of a part. The implementation will use the ConcurrentHashMap class that supports concurrent access to the part name and price. In a multithreaded environment, concurrent data structures, such as the ConcurrentHashMap class, handle operations without the potential for data corruption. Also, this map is an example of caching, which can be useful in improving the performance of applications. ...

Get Learning Network Programming with Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.