title: Why doesn't thread wait for notify()?
body: <p>Why doesn't thread wait for <code>notify()</code>? The thread starts and then goes to the waiting pool, but it proceeds to execute after that moment.   </p>
  
  <pre><code>public class JavaApplication2 {
      public static void main(String [] args) {
         ThreadB b = new ThreadB();
         synchronized(b) {
             b.start();
             try {
                System.out.println("1");
                b.wait();
           } catch (InterruptedException e) {}
            System.out.println("Total is: " + b.total);
         }
       }
   }
    class ThreadB extends Thread {   
      int total;
        @Override
      public void run() {
          synchronized(this) {
              total += 1;
              //notify();
         }
      }
   }
  </code></pre>