title: Finding the biggest number with ForkJoin
body: <p>Without block <code>if delay == 2</code> it works, but doesn't work with it.</p>
  
  <p>Here's ForkJoin's compute:</p>
  
  <pre><code>compute() {
  
      if(lastElem - firstElem == 1)
          return array[firstElem];
  
      if(lastElem - firstElem == 2){
  
          if(array[firstElem] &gt; array[lastElem])
              return array[firstElem];
          else
              return array[lastElem];
      }
  
      int midElem = (firstElem + lastElem) / 2;
  
      MyForkJoinTask left = new MyForkJoinTask(array, firstElem, midElem);
      MyForkJoinTask right = new MyForkJoinTask(array, midElem, lastElem);
  
      left.fork();
      right.fork();
  
      int leftResult = left.join();
      int rightResult = right.join();
  
      if(leftResult &gt; rightResult)
          return leftResult;
      else
          return rightResult;
  
  
  }
  </code></pre>
  
  <p>Here's my main method: </p>
  
  <pre><code>main(String[] args) {
      Random r = new Random();
      for(int i = 0; i &lt; array.length; i++){
          array[i] = r.nextInt();
      }
      MyForkJoinTask root = new MyForkJoinTask(array);
      F_J_POOL.submit(root);
      System.out.println("Result is " + root.join());
  }
  </code></pre>
  
  <p>Short error:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException</p>
    
    <p>at com.bg.fork_join.MainFJ.main(MainFJ.java:24)
    Caused by: java.lang.ArrayIndexOutOfBoundsException
      ... 15 more</p>
    
    <p>Caused by: java.lang.ArrayIndexOutOfBoundsException: 10000
      at com.bg.fork_join.MyForkJoinTask.compute(MyForkJoinTask.java:31)</p>
  </blockquote>
  
  <p>Could you show me where the problem is?</p>