title: Multithreading in java - score list of unknown amount of players
body: <p>I am working on a simple server-client dice-game for university project. The game restriction is that there can be infinite number of players. I am trying to create the list of their scores, but I have no idea how to pass the amount of players, as each time the next player connects, the server accepts new connection, so I cannot prevent next thread from being started.</p>
  
  <p>I was thinking of something like "PLAY" button/boolean variable while waiting for players and right after the game is started, the next thread would be unavailable to start.However, I have no idea how to implement it. Any suggestions? Another idea would also be a good suggestion :)</p>
  
  <p>Here is the code snippet from server:</p>
  
  <pre><code> public void initializeResultList(int amountOfPlayers){
      final ArrayList&lt;Object&gt; resultDescription = new ArrayList();
      ArrayList&lt;Object&gt; zeros = new ArrayList(); 
      resultDescription.add("Player");
      resultDescription.add("One Pair");
      resultDescription.add("Two Pairs");
      resultDescription.add("Three of a kind");
      resultDescription.add("Full House");
      resultDescription.add("Four of a kind");
      resultDescription.add("Five of a kind");
      for (int j = 0; j &lt; resultDescription.size(); j++){
          zeros.add(null);
      }
      resultList.add(resultDescription);
      //fill with nulls, then there will be player Scores
      for (int i = 1; i &lt;= amountOfPlayers; i++){
          resultList.add(zeros);
      }
  
  }
  
   public static void main(String args[]) throws IOException {
  
  
      int portNumber = 444;
  
      ServerSocket serverSocket = null;
  
  
      try {
          serverSocket = new ServerSocket(portNumber);
      } catch (IOException e) {
          e.printStackTrace();
          System.out.println("Error finding port");
          System.exit(1);
      }
  
      // program loop
      do {
          Server server = new Server(serverSocket.accept());
  
          //HERE IS THE PROBLEM!
          server.initializeResultList(2); // here should be passed the amount
          server.start();
      } while (true);
  
  }
  
  @Override
  public void run(){
      System.out.println("Connection accepted");
      System.out.println("Client has successfully connected");
  }
  </code></pre>
  
  <p>Here is code from Player class (it's not the issue right now, but maybe you would like to know how the server and player communicates):</p>
  
  <pre><code>  public static void main (String args[]) throws IOException {
      //Connect to the server
      Socket socket = null;
      int portNumber = 444;
      String str;
      BufferedReader br = null;
      BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = null;
  
      try {
          socket = new Socket(InetAddress.getLocalHost(), portNumber);
          br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
          out = new PrintWriter(socket.getOutputStream(), true);
      } catch (UnknownHostException uhe) {
          System.out.println("Unknown Host");
          System.exit(0);
      }
  
  
      boolean quit = false;
  
      while (!quit) {
  
          str = input.readLine();
          out.println(str);
      }
  
  
  }
  </code></pre>