D
Domagoj Klepac
Anyone worked with NIO (Java 1.5)?
I cannot seem to figure this one - the example from the web works as
expected, but my code doesn't, and I can't find the part which makes
the difference.
My selector.select() or selector.select(timeout) work as expected
until the connection is established. After that, they return 0
immediately. That results in 100% processor usage during the
connection. After the connection(s) is/are closed, select() blocks
again as expected.
Except for 100% processor usage, my program works fine - bytes get
read and written correctly.
Now, I've googled and googled and I've found several possible causes
which don't seem to apply:
- it's not a bug in NIO - all such bugs seem to be fixed by 1.5
- I'm removing the key from the ready set after processing via
iterator.remove()
- I'm not interrupting select with selector.wakeup() (at least not
until shutdown)
- my channels are not blocking, and I'm registering channels with
selector from the same thread that calls selector.select().
From what I know, selector.select() should return 0 only when
interrupted by selector.wakeup(). Selector.select(timeout) should
return 0 only if interrupted by selector.wakeup() or after the timeout
expires.
Are there any other cases where selector.select() returns immediately?
Domchi
I cannot seem to figure this one - the example from the web works as
expected, but my code doesn't, and I can't find the part which makes
the difference.
My selector.select() or selector.select(timeout) work as expected
until the connection is established. After that, they return 0
immediately. That results in 100% processor usage during the
connection. After the connection(s) is/are closed, select() blocks
again as expected.
Except for 100% processor usage, my program works fine - bytes get
read and written correctly.
Now, I've googled and googled and I've found several possible causes
which don't seem to apply:
- it's not a bug in NIO - all such bugs seem to be fixed by 1.5
- I'm removing the key from the ready set after processing via
iterator.remove()
- I'm not interrupting select with selector.wakeup() (at least not
until shutdown)
- my channels are not blocking, and I'm registering channels with
selector from the same thread that calls selector.select().
From what I know, selector.select() should return 0 only when
interrupted by selector.wakeup(). Selector.select(timeout) should
return 0 only if interrupted by selector.wakeup() or after the timeout
expires.
Are there any other cases where selector.select() returns immediately?
Domchi