title: Listening for connections in a separate thread
body: <p>This is part of a messenger project in java. Because clients use direct connections to chat, I want eavry client to listen on some port, and others to make a socket to that address. but when i call ServerSocket.accept() in another thread it appears that all threads have been suspended. which means nothings happens after executing that command. Here is the code which makes new thread. </p>
  
  <pre><code>java.awt.EventQueue.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      try {
                          while(true){
                              System.out.println("flag1");
                              Socket socket = listeningSocket.accept();
                              System.out.println("flag2");
                              new Chat(socket).setVisible(true);;
                              jTextArea1.append("successfully connected\n");
                          }
                      } catch (NullPointerException e) {
                          System.out.println("i know");
                      }
                      catch (IOException e) {
                          e.printStackTrace();
                          jTextArea1.append("error in recieving connection\n");
                      }
                  }
              });
  </code></pre>
  
  <p>any ideas how to solve this?</p>