title: Code requiring "synchronized" works OK without it
body: <p>This is a program from Herbert Schildt's Java Fundamentals to demonstrate synchronization.The method <code>sumArray(int[])</code> is <code>synchronized</code>, and that is a requirement for the program to work correctly. However, when I removed the <code>synchronized</code> keyword, unexpectedly, the program showed almost the same output, and still gave correct results.
  This is the program.     </p>
  
  <pre><code>class SumArray {
          private int sum;
  
          int sumArray(int[] nums) {
              sum = 0; // Reset sum.
              for(int i = 0; i &lt; nums.length; i++) {
                  sum += nums[i];
                  System.out.println("Running total for " + Thread.currentThread().getName() + " is " + sum);
              }
              return sum;
          }
      }
  
      class SumThread implements Runnable {
          static SumArray sa = new SumArray();
          Thread thrd;
          int[] a;
          int answer;
  
          public SumThread(String name, int[] nums) {
              thrd = new Thread(this, name);
              a = nums;
              thrd.start();
  
          }
  
          @Override public void run() {
              System.out.println(thrd.getName() + " starting.");
              answer = sa.sumArray(a);
              System.out.println("Sum for " + thrd.getName() + " is " + answer);
              System.out.println(thrd.getName() + " terminating.");
          }
  
      }
  
      public class SyncExample {
  
          public static void main(String[] args) {
              int[] a = new int[] {1, 2, 3, 4, 5, 6};
  
              SumThread mt1 = new SumThread("Thread #1", a);
              SumThread mt2 = new SumThread("Thread #2", a);
  
              try {
                  mt1.thrd.join();
                  mt2.thrd.join();
              } catch(InterruptedException e) {
                  e.printStackTrace();
              }
          }
  
      }
  </code></pre>
  
  <p>Output.</p>
  
  <pre><code>Thread #1 starting.
  Running total for Thread #1 is 1
  Running total for Thread #1 is 3
  Running total for Thread #1 is 6
  Running total for Thread #1 is 10
  Running total for Thread #1 is 15
  Running total for Thread #1 is 21
  Sum for Thread #1 is 21
  Thread #1 terminating.
  Thread #2 starting.
  Running total for Thread #2 is 1
  Running total for Thread #2 is 3
  Running total for Thread #2 is 6
  Running total for Thread #2 is 10
  Running total for Thread #2 is 15
  Running total for Thread #2 is 21
  Sum for Thread #2 is 21
  Thread #2 terminating.
  </code></pre>
  
  <p>Is there something wrong with my computer, or are threads supposed to be this strange?</p>