title: When do threads share objects? - Java
body: <p>Hey I'm trying to grasp Threads as a concept.
  Let me draw you a scenario</p>
  
  <pre><code>class A {
      private int counter = 0;
  
      public void add() {
          counter++;
      }
  
      public int getCounter() {
          return counter;
      } 
  }
  
  class B implements Runnable {
      public void run() {
          A a = new A();
          a.add();
          a.add();
      }
  }
  
  class C implements Runnable {
      public void run() {
          A a = new A();
          System.out.println(a.getCounter());
      }
  }
  </code></pre>
  
  <p>What does the <code>System.out.println</code> give me when I run <code>C</code>?
  I'm guessing it gives me 0 because they each created an instance of <code>A</code>.</p>
  
  <p>If thats true, how would you share that object between the threads?</p>