rendered paste bodypublic class lol { public static void main(String[] args) { demo2(); } public static void demo1() { final Object lock = new Object(); Thread a = new Thread(new Runnable() { public void run() { synchronized (lock) { try { lock.wait(); } catch (InterruptedException e) { } System.out.println("A"); } } }); Thread b = new Thread(new Runnable() { public void run() { synchronized (lock) { lock.notify(); System.out.println("B"); } } }); a.start(); b.start(); }public static void demo2() {final Object lock = new Object();Thread a = new Thread(new Runnable() {public void run() {synchronized (lock) {try {lock.notify();} catch(Exception ex) {}}synchronized (lock) {try {lock.wait();} catch (InterruptedException e) {}System.out.println("A");}}});a.start();synchronized (lock) {lock.wait();}synchronized (lock) {lock.notify();System.out.println("B");}}