> Ok, I wrote the code like this:
> mykey=channel.register(selector, SelectionKey.OP_READ|SelectionKey.OP_WRITE);
Didn't you read what I posted at all?
> channel.send(x, new InetSocketAddress(ip, port));
Ditto.
> It seems the code works well, are there any more suggestions?? thx!
That code would still exhibit your original problem. Try what I suggested.
lightning - 20 Feb 2008 05:29 GMT
Of course I got what you say and the origianl problem had already
gone,cpu now costs nothing.
In fact you did not see my trick here ;)
look at the handle method:
> queue.clear();
> key.interestOps(SelectionKey.OP_READ);
You see,although I registered WRITE in the beginning,but when the
first WRITE fires,
the handle method can unregister WRITE after doing nothing.
So whatever I register at first does not matter and yes if I didn't
register OP_WRITE at start it would seem more clear.
the key is the code above in "handle" method and the following:
> if(!queue.isEmpty()){
> mykey.interestOps(SelectionKey.OP_READ|SelectionKey.OP_WRITE);
> }
> > Ok, I wrote the code like this:
> > mykey=channel.register(selector, SelectionKey.OP_READ|SelectionKey.OP_WRITE);
[quoted text clipped - 4 lines]
>
> That code would still exhibit your original problem. Try what I suggested.
EJP - 20 Feb 2008 09:46 GMT
So all you need to do now is implement the rest of what I said ...