title: DatagramChannel  packet listener taking high CPU
body: <p>I have a packet Listener Thread in Java for UDP packets along with 2-3 other threads.</p>
  
  <p>It was running fine till today but now the process javaw.exe has started using CONSTANT 50% CPU.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>public class PacketListenerThread implements Runnable {
      private SocketAddress receivedSocketAddress;
      private DatagramChannel channel;
      private ExecutorService pool;
  
      public PacketListenerThread(DatagramChannel channel, ExecutorService pool) {
          this.channel = channel;
          this.pool = pool;
      }
  
      @Override
      public void run() {
          while (true) {
              receivedSocketAddress = null;
              ByteBuffer recvbuf = ByteBuffer.allocate(1400);
              recvbuf.clear();
              try {
                  receivedSocketAddress = channel.receive(recvbuf);
              } catch (IOException e) {
                  e.printStackTrace();
              }
              if (receivedSocketAddress != null) {
                  pool.submit(new PacketHandlerRunnable(new TaskObject(receivedSocketAddress, recvbuf)));
              }
          }
      }
  }
  </code></pre>
  
  <p>I have stopped all other threads but this thread still uses "CONSTANT" 50% CPU .</p>