What is the difference between an iterative server and a concurrent server, and which one should I be using?

Tim Rohaly

In brief, an iterative server handles clients one at a time, in series, while a concurrent server handles many clients at the same time, in parallel.

When a server invokes the accept() method of a ServerSocket object, the server thread blocks until a client connects to the server. The server must handle the client's request then go back to listening for further client connections. In an iterative server, the main server method handles each client request in its entirety before moving on to accept the next request. Iterative servers are good when the requests take a known, short period of time. For example, requesting the current day and time from a time-of-day server.

While iterative servers are simple, they are severely limited in their performance because only one client at a time can be handled. In particular, when the amount of processing needed to handle a client request is unknown a priori (i.e., depends on the request itself), iterative servers are unacceptable. A TELNET session, for instance, can take an unbounded amount of time, so the server should not wait until that session is over before accepting new clients.

To overcome this limitation of iterative servers, a separate thread can be created to handle each client session, allowing the server to deal with multiple clients simultaneously. This is known as a concurrent server: the main server method launches a thread to handle each client request, so multiple clients can simultaneously interact with the server while the server continues to listen for additional clients.