~/ learn/ comp-348/ cards/ One at a time is a queue: going multithreaded
1 of 5

Hand the connection off and go straight back to accept()

Hand the connection off and go straight back to accept()

Answer

while (true) { // no try-with-resources here: the socket outlives this block Socket client = listener.accept(); new Thread(new DaytimeHandler(client)).start(); }

The accepting thread does two things and nothing else: take the connection off the kernel queue, and give it to somebody. It is back inside `accept()` within microseconds, so the queue drains at handshake speed rather than at handler speed.

Harold 4e ch9 §Multithreaded Servers

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/c1522018-69e3-4cd0-84fd-8dbd48f458e5/flashcard utf-8 LF