title: Java share a variable between two threads
body: <p>I have two threads. One invokes the update method of a class that modifies a variable. Another invokes the update method of a class that reads the variable. Only one thread writes and one (or more) threads read that variable. What do I need to do in terms of concurrency, since I am new to multi-threading?</p>
  
  <pre><code>public class A
  {
      public int variable; // Does this need to be volatile?
         // Not only int, could also be boolean or float.
      public void update()
      {
          // Called by one thread constantly
          ++variable;
          // Or some other algorithm
          variable = complexAlgorithm();
      }
  }
  
  public class B
  {
      public A a;
      public void update()
      {
          // Called by another thread constantly
          // I don't care about missing an update
          int v = a.variable;
          // Do algorithm with v...
      }
  }
  </code></pre>
  
  <p>Thanks,</p>