title: How to get update message/property from second level threads in JavaFX?
body: <p>In a JavaFX application, I have a master thread which listens to the multiple clients through socket, and for each client connection separate thread is created for communication with the client. I want to display messages from all the clients on the JavaFX scene (through property binding or some other way). I tried with Task and Service as explained in the Concurrency in JavaFX tutorial <a href="https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/concurrency.htm" rel="nofollow">https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/concurrency.htm</a>. I am able to get the message from the master thread through updateMessage, but couldn't figure out how to get the messages from the second level threads created for client communications. The sample code I tried is given below.</p>
  
  <pre><code>public class SocketService
      {
          int portNumber;
  
          public SocketService(int portNumber)
          {
              this.portNumber = portNumber;
  
              Task task = new Task&lt;Void&gt; ()
              {
                  @Override
                  public Void call()
                  {
                      try (ServerSocket serverSocket = new ServerSocket(portNumber))
                      {
                          while (true)
                          {
                              ClientService cs = new ClientService(serverSocket.accept());
                              cs.start();
                              updateMessage("Connected");
                          }
                      } catch (IOException e)
                      {
                          System.out.println("Exception!!! "+e.getMessage());
                      }
                      return null;
                  }
              };
             new Thread(task).start();
          }
      }
  
      class ClientService extends Service&lt;Void&gt;
      {
          Socket connectSocket;
          public ClientService(Socket connectSocket)
          {
              this.connectSocket = connectSocket;
          }
  
          @Override
          public Task&lt;Void&gt; createTask()
          {
              return new Task&lt;Void&gt;()
              {
                  @Override public Void call()
                  {
                      try (PrintWriter out = new PrintWriter(connectSocket.getOutputStream(), true);
                           BufferedReader in = new BufferedReader(new InputStreamReader(connectSocket.getInputStream()));)
                      {
                          String inText;
  
                          while ((inText = in.readLine()) != null)
                          {
                              System.out.println(inText);
                              updateMessage(inText); // want to get this message updated in JavaFX
                          }
                      } catch (IOException e)
                      {
                          System.out.println("Exception!!! "+e.getMessage());
                      }
                      return null;
                  }
              };
          }
      }
  </code></pre>
  
  <p>Thanks in advance for your help.</p>