title: Getting the output of a Thread
body: <p>What do you think is the best way for obtaining the results of the work of a thread? Imagine a Thread which does some calculations, how do you warn the main program the calculations are done?</p>
  <p>You could poll every X milliseconds for some public variable called &quot;job finished&quot; or something by the way, but then you'll receive the results later than when they would be available... the main code would be losing time waiting for them. On the other hand, if you use a lower X, the CPU would be wasted polling so many times.</p>
  <p>So, what do you do to be aware that the Thread, or some Threads, have finished their work?</p>
  <p>Sorry if it looks similar to this other <a href="https://stackoverflow.com/questions/289434/how-to-make-a-java-thread-wait-for-another-threads-output">question</a>, that's probably the reason for the <em>eben</em> answer, I suppose. What I meant was running lots of threads and know when all of them have finished, without polling them.</p>
  <p>I was thinking more in the line of sharing the CPU load between multiple CPU's using batches of Threads, and know when a batch has finished. I suppose it can be done with <strong>Future</strong>s objects, but that blocking <em><strong>get</strong></em> method looks a lot like a hidden lock, not something I like.</p>
  <p>Thanks everybody for your support. Although I also liked the answer by <em><strong>erickson</strong></em>, I think <em><strong>saua</strong></em>'s the most complete, and the one I'll use in my own code.</p>