title: How to split Math work into worker threads Java
body: <p>I'm developing a Java app that calcuates numbers to powers. I would like to take advantage of my quad core computer, as only one core is being used with this application. I've looked at different tutorials on how to syncronize threads, but I don't really get it. My code is below:</p>
  
  <pre><code>public class Bignum{
  
  public static void main(String[] args){
  
      Random generator = new Random();   
      long start = System.nanoTime();   
      Random generator1 = new Random();
  
  for (long i=0; i&lt;9000;i++){
  
      int power = generator1.nextInt (17) + 2;
      int power1 = generator1.nextInt (25) + 2;
      int power2 = generator1.nextInt (72) + 2;
  
      BigInteger num = BigInteger.valueOf (generator.nextInt (7895) + 1);
      BigInteger num1 = BigInteger.valueOf (generator.nextInt (1250) + 1);
      BigInteger num2 = BigInteger.valueOf (generator.nextInt (9765) + 1);
  
      BigInteger add = num.pow(power);
      BigInteger add1 = num1.pow(power1);
      BigInteger add2 = num2.pow(power2);
  
      BigInteger sum = add.add(add1);
  
  }
  
  }
  }
  </code></pre>
  
  <p>So, for example, how could I have one thread do this:</p>
  
  <pre><code>    int power = generator1.nextInt (17) + 2;
      int power1 = generator1.nextInt (25) + 2;
      int power2 = generator1.nextInt (72) + 2;
  </code></pre>
  
  <p>Another do this:</p>
  
  <pre><code>    BigInteger num = BigInteger.valueOf (generator.nextInt (7895) + 1);
      BigInteger num1 = BigInteger.valueOf (generator.nextInt (1250) + 1);
      BigInteger num2 = BigInteger.valueOf (generator.nextInt (9765) + 1);
  </code></pre>
  
  <p>Another this:</p>
  
  <pre><code>    BigInteger add = num.pow(power);
      BigInteger add1 = num1.pow(power1);
      BigInteger add2 = num2.pow(power2);
  </code></pre>
  
  <p>And the last one do this:</p>
  
  <pre><code>    BigInteger sum = add.add(add1);
  </code></pre>
  
  <p>How could I do that? Also, how could I still repeat that 9000 times? Thank you for your help.</p>