title: sun.rmi.transport.tcp.TCPTransport uses 100% CPU
body: <p>I'm developping a communication library based on NIO's non-blocking SocketChannels so I can use <code>select</code> to keep my thread low on CPU usage (and getting faster reaction time to other events).
  <code>SocketChannel</code> are created externally to my thread and added to the list it handles, marking them as non-blocking and adding them to a <code>Selector</code> for READ operations (and WRITE when needed, but that does not happen in my problem).</p>
  
  <p>I have a little Swing application for tests, running locally, that can be either a client or server: the client one connects to the server one and they can send each other messages. Pretty simple and works fine, excepts for the CPU which tops 100% (50% for each jvm) as soon as the connection is established between client and server.</p>
  
  <p>Running <code>jvisualvm</code> shows me that <code>sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run()</code> uses 98% of the application time, counting only 3 method calls!<br/>
  A forced stack trace shows it's blocking on the <code>read</code> operation on a <code>FilteredInputStream</code>, on a <code>Socket</code>.</p>
  
  <p>I'm a little puzzled as I don't use RMI (though I can understand NIO and RMI can share the "transport" code part). I have seen a few similar questions but each were specifically using RMI, which I'm not. The answers I've seen is that this <code>ConnectionHandler.run()</code> method is responsible for marshalling/unmarshalling things, when here I get 100% CPU without any network traffic. I can only infer an active wait on the sockets but that sounds odd, especially with non-blocking <code>SocketChannel</code>...</p>
  
  <p>Any idea would be greatly appreciated!</p>