title: Running multiple syncronized method
body: <p>I have to create a situation where 3 people are having a conversation. The situation will be like this.<br>
  A is talking while B and C won't do anything.<br>
  B is talking while A and C won't do anything.<br>
  C is talking while B and A won't do anything.<br>
  This means only one thread will remain active at a time. As I am new to this, first
  I am trying to print</p>
  <p>A</p>
  <p>B</p>
  <p>C</p>
  <p>3 times using 3 synchronized methods. But instead of these it is printing</p>
  <p>A</p>
  <p>C</p>
  <p>B</p>
  <p>here is my code:</p>
  <pre class="lang-java prettyprint-override"><code>    public class Chat {
      synchronized void chatA(){
          for(int i = 0; i&lt;3; i++) {
              System.out.println(&quot;A&quot;);
              try {
                  wait();
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              notify();
          }
      }
      synchronized void chatB(){
          for(int i=0; i&lt;3; i++) {
              System.out.println(&quot;B&quot;);
              
              try {
                  wait();
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              notify();
          }
          
      }
      synchronized void chatC(){
          for(int i=0; i&lt;3; i++) {
              System.out.println(&quot;C&quot;);
              notify();
              try {
                  wait();
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              
          }
      }
      public static void main(String[] args){
          Chat chat = new Chat();
          Thread t1 = new Thread() {
              public void run() {
                  chat.chatA();
              }
          };
          t1.start();
          Thread t2 = new Thread() {
              public void run() {
                  chat.chatB();   
              }
          };
          t2.start();
          Thread t3 = new Thread() {
              public void run() {
                  chat.chatC();   
              }
          };
          t3.start();
      }
  }
  </code></pre>
  <p>Please tell me what is I am missing.</p>