title: One thread per client. Doable?
body: <p>I'm writing a Java server which uses plain sockets to accept connections from clients. I'm using the fairly simple model where each connection has its own thread reading from it in blocking mode. Pseudo code:</p>
  
  <pre><code>handshake();
  
  while(!closed) {
    length = readHeader(); // this usually blocks a few seconds
    readMessage(length);
  }
  
  cleanup();
  </code></pre>
  
  <p>(Threads are created from an <code>Executors.newCachedThreadPool()</code> so there shouldn't be any significant overhead in starting them)</p>
  
  <p>I know this is a bit of a naive setup and it wouldn't really scale well to many connections if the threads were dedicated OS threads. However, I've heard that multiple threads in Java can share one hardware thread. Is that true?</p>
  
  <p>Knowing that I'll be using the Hotspot VM on Linux, on a server with 8 cores and 12GB of RAM, do you think this setup will work well for thousands of connections? If not, what are the alternatives?       </p>