title: In Java, how to pass the objects back to Main thread from worker threads?
body: <p>In Java, how to pass the objects back to Main thread from worker threads? Take the following codes as an example:</p>
  
  <pre><code>  main(String[] args) {
  
      String[] inputs;
      Result[] results;
      Thread[] workers = new WorkerThread[numThreads];
  
      for (int i = 0; i &lt; numThreads; i++) {
          workers[i] = new WorkerThread(i, inputs[i], results[i]);
          workers[i].start();
      } 
  
      ....
    }
    ....
  
  class WorkerThread extends Thread {
      String input;
      int name;
      Result result;
  
      WorkerThread(int name, String input, Result result) {
          super(name+"");
          this.name = name;
          this.input = input;
          this.result = result;
      }
  
      public void run() {
          result  = Processor.process(input);
      }
  }
  </code></pre>
  
  <p>How to pass the <code>result</code> back to <code>main</code>'s <code>results[i]</code> ?</p>
  
  <p>How about passing <code>this</code> to <code>WorkerThread</code>, </p>
  
  <pre><code>workers[i] = new WorkerThread(i, inputs[i], results[i], this);
  </code></pre>
  
  <p>so that it could</p>
  
  <pre><code>mainThread.reults[i] = Processor.process(inputs[i]);
  </code></pre>