~/ 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/45470972-d9fb-4bf3-bdf5-ad264cfb8ca2/flashcard utf-8 LF