First off, here's my computer's configuration.
Red Hat 9, using j2sdk 1.4.2, packages I'm having trouble with
Java.NIO
The Problem:
java.NIO is supposedly non blocking. I've created a thread pool in
which each thread continuously checks sockets (or channels) for
incoming events. If a thread finds an incoming event, it removes the
readOps from the InterestOps. It does this in order to prevent the
other threads from repeating the events. The thread then reads/writes
data from/to the network socket and then tries to re-enable the
various interest operations so we can check for future events that
occur on this socket. It deadlocks on Linux here.. I can't re-enable
the interest operations.
This is what the java docs say about selection keys:
"Selection keys are safe for use by multiple concurrent threads. The
operations of reading and writing the interest set will, in general,
be
synchronized with certain operations of the selector. Exactly how this
synchronization is performed is implementation-dependent: In a naive
implementation, reading or writing the interest set may block
indefinitely if a selection operation is already in progress; in a
high-performance implementation, reading or writing the interest set
may
block briefly, if at all. In any case, a selection operation will
always
use the interest-set value that was current at the moment that the
operation began."
I can't see how one can use multiple threads with NIO given the
current behavior. Is there a way to get around this?. I need multiple
threads to check sockets for events. I will not change the kernel on
Redhat, even though I've tried and it still does not work. |