title: Accessing a variable of a thread from another thread in java
body: <p>I'm trying to access and modify a variable of a thread in another thread in java, and I really don't know how to do this.</p>
  <p>ex :</p>
  <pre><code>Runnable r1 = new Runnable() {
      int value = 10;
      public void run() {
          // random stuff
      }
  }
  Runnable r2 = new Runnable() {
     public void run() {
          // of course the bellow line will not work
          r1.value--; // I want here to be able to decrement the variable &quot;value&quot; of r1
      }
  }
  Thread t1 = new Thread(r1);
  Thread t2 = new Thread(r2);
  t1.start();
  t2.start();
  </code></pre>
  <p>Is there any way to create a getter and setter for a thread in java?</p>
  <p><em>Edit:</em> the answers were good, but I was not clear in my question, I will try asking a better question</p>