title: Divide calculations among multiple threads
body: <p>I've just started working with threads in java. I have a simple algorithm that does a lot of calculations. What I need to do is to divide those calculations among different threads. It looks like this:</p>
  
  <pre><code>while(...) {
        ....
        doCalculations(rangeStart, rangeEnd);
  }
  </code></pre>
  
  <p>And what I want to do is something like this:</p>
  
  <pre><code>while(...) {
       ...
       // Notify N threads to start calculations in specific range
  
       // Wait for them to finish calculating
  
       // Check results
  
       ... Repeat
  
  }
  </code></pre>
  
  <p>Calculating threads don't have to have a critical section or be synchronized between each other, because they don't change any shared variables.</p>
  
  <p>What I can't figure out is how to order threads to start and wait them to finish.</p>
  
  <p>thread[n].start() and thread[n].join() throws an exception.</p>
  
  <p>Thank you!</p>