title: Sorting Arraylist using Bubblesort in parallel with fork/join pool
body: <p>So what I am trying to do is sort an ArrayList using Fork/Join pool. The algorithm that I will use to sort doesn't matter: I just choosed a random one for here. What matters is how I am supposed to use the Recursive task with fork/join pool so that the ArrayList will keep on splitting until the ArrayList size reaches a certain number (like 1000) then it will perform the sorting and then it will join back into one ArrayList. 
  Here is my code:</p>
  
  <p>assignment5</p>
  
  <pre><code>public class assignment5 {
  
      ArrayList&lt;Integer&gt; numbers = new ArrayList&lt;&gt;();
  //lets say this arraylist is full with random numbers
  
      public void run(){
  
          Instant start = Instant.now();
  
          MyRecursiveTask myRecursiveTask = new MyRecursiveTask(numbers);
          ArrayList&lt;Integer&gt; mergedResult = ForkJoinPool.invoke(myRecursiveTask);
  
          Instant end = Instant.now();
  
          Duration duration = Duration.between(start, end);
          System.out.println("Seconds: " + duration.getSeconds());
  
      }
  
  }
  </code></pre>
  
  <p>over here in assignment5 gives me error on
  <code>ForkJoinPool.invoke(myRecursiveTask);</code>
  it says non static method invoke connot be reffereced from a static content</p>
  
  <p>MyRecursiveTask</p>
  
  <pre><code>    private List&lt;Integer&gt; numbers;
  
      protected List&lt;Integer&gt; compute() {
          //numbers here is the same as in assignment 5
          //if work is above threshold, break tasks up into smaller tasks
          if(this.numbers.size() &gt; 1000) {
              System.out.println("Splitting workLoad : " + this.numbers.size());
  
              List&lt;MyRecursiveTask&gt; subtasks = new ArrayList&lt;MyRecursiveTask&gt;();
              subtasks.addAll(createSubtasks());
  
              for(MyRecursiveTask subtask : subtasks){
                  subtask.fork();
              }
  
              for(MyRecursiveTask subtask : subtasks) {
                  subtask.join();
              }
              return numbers;
  
          } else {
              System.out.println("Doing workLoad myself: " + this.numbers.size());
              bubbleSort(numbers);
          }
          return numbers;
      }
  
      private List&lt;MyRecursiveTask&gt; createSubtasks() {
          List&lt;MyRecursiveTask&gt; subtasks = new ArrayList&lt;MyRecursiveTask&gt;();
  
          List&lt;Integer&gt; list1 = numbers.subList(0,numbers.size()/2);
          List&lt;Integer&gt; list2 = numbers.subList(numbers.size()/2, numbers.size());
  
          MyRecursiveTask subtask1 = new MyRecursiveTask(list1);
          MyRecursiveTask subtask2 = new MyRecursiveTask(list2);
  
          subtasks.add(subtask1);
          subtasks.add(subtask2);
  
          return subtasks;
      }
      public void bubbleSort(List&lt;Integer&gt; numbers){//bubble sort alg here}
  }
  </code></pre>