title: BufferedReader.read() eating 100% of CPU
body: <p>I have a JAVA game server that uses 1 thread per TCP connection. (I know it's bad but i'll have to keep it this way for now). On a (3.2Ghz 6cor x2 machine, 24GB RAM, windows server 2003 64bits) and here is a piece of the code:</p>
  
  <pre><code>public void run()
  {
      try
      {   
          String packet = "";
          char charCur[] = new char[1];
  
          while(_in.read(charCur, 0, 1)!=-1 &amp;&amp; Server.isRunning)
          {
              if (charCur[0] != '\u0000' &amp;&amp; charCur[0] != '\n' &amp;&amp; charCur[0] != '\r')
              {
                  packet += charCur[0];
              }else if(!packet.isEmpty())
              {
                  parsePlayerPacket(packet);
                  packet = "";
              }
          }
  
      }catch(Exception e)
      {
          e.printStackTrace();
      }
      finally
      {
          try{
              kickPlayer();
          }catch(Exception e){e.printStackTrace();};
  
          Server.removeIp(_ip);
      }
  }
  </code></pre>
  
  <p>After about 12 hours or more of server upTime (and about 3.000 players connected) the server starts eating 100% of all the 12 CPUs for ever, until I manually reboot the JAVA application. So the game starts lagging verry bad and my players starts complaining.</p>
  
  <p>I have tried profiling the application and here is what I came up with:</p>
  
  <p><img src="https://i.stack.imgur.com/IzdtA.jpg" alt="Screenshot of my profiling result"></p>
  
  <p>So I am guessing that the problem is coming from here:</p>
  
  <pre><code>while(_in.read(charCur, 0, 1)!=-1 &amp;&amp; Server.isRunning)
  </code></pre>
  
  <p>knowing that the variable "_in" is a reader of the socket input : (_in = new BufferedReader(new InputStreamReader(_socket.getInputStream()))).</p>
  
  <p>Why on earth _in.read() takes so much CPU after a long server upTime?</p>
  
  <p>I have tried putting a Thread.sleep(1); and more inside the While loop, but doesn't do anything, I guess the problem is inside of the BufferedReader.read() method.</p>
  
  <p>Does anyone have any idea of what can cause this?? And how to fix it?</p>