title: How can I implement a threaded UDP based server in Java?
body: <p>How can I implement a threaded UDP based server in Java ?</p>
  
  <p>Basically what I want, is to connect multiple clients to the server, and let each client have his own thread. The only problem is, that I don't know how to check if a client is trying to connect to the server and spawn a new thread for it.</p>
  
  <pre><code>boolean listening = true;
  
  System.out.println("Server started.");
  
  while (listening)
      new ServerThread().start();
  </code></pre>
  
  <p>In this case the server will spawn new threads until it runs out of memory.
  Here's the code for the ServerThread ( I think I need here a mechanism that stalls the creation of the ServerThread until a client tries to connect.</p>
  
  <pre><code>public ServerThread(String name) throws IOException 
  {
      super(name);
      socket = new DatagramSocket();
  }
  </code></pre>
  
  <p>So fathers of Java programming please help. </p>