title: Passing variables between threads in Java
body: <p>I have 10 identical threads (differentiated only by primary key from 1 to 10) that I create in the main class. In each thread I need to read field in the previous thread i.e. in thread 5 I need to read this field in thread 4. The question is how can I do it?  </p>
  
  <pre><code>public class Player extends Thread {
  
  private Integer playerNumber;
  
  public char lastDigit;
  
  public Player(Integer playerNumber) {
      super();
      this.playerNumber = playerNumber;
  }
  
  public synchronized char getDigit(){
      return this.lastDigit;
  }
  
  public synchronized void setDigit(char digit){
      massage += digit;
      this.lastDigit = digit;
      try {
          Thread.sleep(1);
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
  }
  
  public void run(){
  
  }
  </code></pre>
  
  <p>I need to read the lastDigit field.</p>
  
  <p>Thanks in advance :)</p>