title: How do the threads share the field variable of the same instance who creates them?
body: <p>I want to test the interface Runnable. 
  Create an instance of a class who implements interface Runnable. And then create three threads by the same instance. Observe how the threads share the field variable of the instance.
  <strong>Two questions:
  1. Why are the two results not like the sequence of "20, 19, 18....1, 0"?
  2. Why are the two results different from each other? (I run the code twice.)</strong>
  The code is as following:</p>
  
  <pre><code>public class ThreadDemo2 {
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          TestThread tt = new TestThread();
          Thread t1 = new Thread(tt);
          Thread t2 = new Thread(tt);
          Thread t3 = new Thread(tt);
          t1.start();
          t2.start();
          t3.start();
      }
  }
  class TestThread implements Runnable {
      public int tickets = 20;
      public void run(){
          while (tickets &gt;= 0){
              System.out.println(Thread.currentThread().getName() + ":the number of tickets is " + tickets--);
          }
      }
  }
  </code></pre>
  
  <p>I run the code twice. The two results are shown below.
  <strong>The First time:</strong></p>
  
  <pre><code>Thread-1:the number of tickets is 20
  Thread-2:the number of tickets is 18
  Thread-2:the number of tickets is 16
  Thread-0:the number of tickets is 19
  Thread-2:the number of tickets is 15
  Thread-1:the number of tickets is 17
  Thread-2:the number of tickets is 13
  Thread-0:the number of tickets is 14
  Thread-2:the number of tickets is 11
  Thread-1:the number of tickets is 12
  Thread-2:the number of tickets is 9
  Thread-0:the number of tickets is 10
  Thread-2:the number of tickets is 7
  Thread-1:the number of tickets is 8
  Thread-2:the number of tickets is 5
  Thread-0:the number of tickets is 6
  Thread-2:the number of tickets is 3
  Thread-1:the number of tickets is 4
  Thread-2:the number of tickets is 1
  Thread-0:the number of tickets is 2
  Thread-1:the number of tickets is 0
  </code></pre>
  
  <p><strong>The second time:</strong></p>
  
  <pre><code>Thread-0:the number of tickets is 19
  Thread-2:the number of tickets is 18
  Thread-2:the number of tickets is 16
  Thread-2:the number of tickets is 15
  Thread-1:the number of tickets is 20
  Thread-2:the number of tickets is 14
  Thread-2:the number of tickets is 12
  Thread-2:the number of tickets is 11
  Thread-0:the number of tickets is 17
  Thread-2:the number of tickets is 10
  Thread-2:the number of tickets is 8
  Thread-1:the number of tickets is 13
  Thread-1:the number of tickets is 6
  Thread-1:the number of tickets is 5
  Thread-2:the number of tickets is 7
  Thread-0:the number of tickets is 9
  Thread-2:the number of tickets is 3
  Thread-1:the number of tickets is 4
  Thread-2:the number of tickets is 1
  Thread-0:the number of tickets is 2
  Thread-1:the number of tickets is 0
  </code></pre>