~/ 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/88477e33-51b3-4803-9c03-6ab9787ab53e/flashcard utf-8 LF