~/ learn/ comp-348/ cards/ Selectors: one thread, many connections
1 of 6

Register a channel and hand it its per-connection state

Register a channel and hand it its per-connection state

Answer

client.configureBlocking(false); SelectionKey key = client.register(selector, SelectionKey.OP_READ); key.attach(response.duplicate());

register() lives on the channel and requires non-blocking mode first. The attachment carries this connection state; duplicate() gives this client its own position and limit over the one shared response buffer.

Harold 4e ch11 §Readiness Selection

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/f4e5e4c8-0f27-46ce-83f1-1d4322b4e506/flashcard utf-8 LF