title: Thread.sleep and BufferedReader.readLine use the most cpu cycles in my java tcp server. Why?
body: <p>Good evening,</p>
  
  <p>I'm developing a java tcp server for communication between clients.</p>
  
  <p>At this point i'm load testing the developed server.</p>
  
  <p>This morning i got my hands on a profiler (yourkit) and started looking for problem spots in my server.</p>
  
  <p>I now have 480 clients sending messages to the server every 500 msec. The server forwards every received message to 6 clients.</p>
  
  <p>The server is now using about 8% of my cpu, when being on constant load.</p>
  
  <p>My question is about the java functions that uses the most cpu cycles.</p>
  
  <p>The java function that uses the most cpu cycles is strangly "Thread.sleep", followed by "BufferedReader.readLine".</p>
  
  <p>Both of these functions seem to block the current thread while waiting for something (sleep waits for a few msec, readline waits for data).</p>
  
  <p>Can somebody explain why these 2 functions take up that much cpu cycles? I was also wondering if there are alternative approaches that use less cpu cycles.</p>
  
  <p>Kind regards,
  T. Akhayo</p>