Problems with non-blocking select with java.nio?

No. Just remove the key from the selected set. Usually this is done via iterator.remove().

If you cancel they key it will never be selected again. It's pointless. You don't need the second selector, or the extra thread either.

That's what NIO is for. You can handle it all with the original selector within the original thread. It's probably caused by strange code.

Redo it as above and see if it still happens. If so, post some code here. You would need to read the Berkeley Sockets API or a good book such as Stevens, Unix Network Programming, or mine ;-).

Thanks for the answers, going to try them right away. As for (4) - I didn't mean windows Sockets, I meant the nio part. Like how the selector works, etc.– Max Nov 20 '10 at 11:25 Also, I'm not sure about number (2).

The extra modifications over the packets could take some long time (like 2-5 seconds), while I want to maintain several clients connected at once. So which way should I do it? – Max Nov 20 '10 at 11:28 NIO just uses select() under the hood, to a first approximation.

What you say about (2) doesn't change anything. You just select until something happens, then you handle it: OP_READ or OP_ACCEPT. – EJP Nov 20 '10 at 11:31 @Max So you let the (single) selector itself block -- it can monitor n channels, maintain read/write-able data (on read-able read data, but don't monitor for write-able until data is ready...), wake the selector up as needed, etc. It's ... tedious.

– pst Nov 20 '10 at 11:32 @EJP Seems like (1) was the problem. Once I changed it to remove iterator it all miraculously started to work. However, could you please explain what exactly does cancel() do?

And why should I care that this key is never selected again (I'm already processing it)? Or is it canceling all keys in selector? Thanks.

– Max Nov 20 '10 at 11:53.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions