flush() freezes on a SocketChannel

Hi all,

I’ve been doing some interruptible socket I/O recently, and things looked like they worked great. I had a ServerSocketChannel in its own thread, looping on accept() until the thread is interrupted, and spawning per-client threads for each client connection.

Each client sends text to the server, and the corresponding client handler threads work fine, their BufferedReader’s (over the channels’ socket’s input streams) returning from readLine smoothly, etc.

However, it seems that as soon as I also bind Writers to the sockets’ output streams, attempting to flush those freezes, no matter what. Be it on the server or client side, the flush() operation on output streams locks up. It will then, much later on, unfreeze–sometimes.

I have no idea what I’m doing wrong. Maybe, just maybe, this would have some relation to my not using a Selector? I just create a ServerSocketChannel, bind its socket, and start a trivial accept loop…

Any idea?