I am developing an Android app in which I am using SocketChannel with Selector for sending network requests to my server.
I have a selector on one threads which has registered for OP_CONNECT
, OP_WRITE
and OP_READ
and which calls the select()
method to receive these events.
can anybody suggest me correct way of doing the multi-threaded registration of SocketChannel with a single Selector ?
The time-consuming part is the actual read from/write to the channels. So basically you would
select()
. Once return value > 0, get the set of selection keys and determine if you want to read/write on the associated channels.Runnable
instances if you want zero object loop.