title: Java Multithreading - How would I spawn two additional threads to increment values within an array?
body: <p>Scenerio: </p>
  
  <ol>
  <li>I have an integer array of 15 indexes. (each populated with some value) </li>
  <li>I want two threads to add two (+2) to the value of the index. Each being aware which index has already been added.</li>
  <li>Then join the threads and exit. </li>
  </ol>
  
  <p>So far (to where I made it) I'm simply implementing the Runnable interface and supplying the array to computed inside of runnable. I'm stuck with how to do this handshaking from here. Thanks in advance for the help</p>
  
  <pre><code>public class FooRunnable implements Runnable
  {
      private int[] myArray = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
  
      @Override
      public void run()
      {
          for(int i=0; i&lt;myArray.length; i++)
          {
              myArray[i] = myArray[i] +2;
              System.out.println("Thread "+Thread.currentThread().getName()+" Finished index: "+i);
              atomicCount.incrementAndGet();
          }
      }
  
      public static void main(String[] args)
      {
          FooRunnable r = new FooRunnable();
          Thread t1 = new Thread(r);
          Thread t2 = new Thread(r);
          t1.setName("Thread One");
          t2.setName("Thread Two");
          t1.start();
          t2.start();
      }
  }
  </code></pre>
  
  <p>Results (Goal):</p>
  
  <p>When program exits. the array should have each element of the array incremented by two via two different threads.</p>