public class TL { public synchronized void waitOne() { try { Thread.sleep(1000); } catch (Exception e) { } waitTwo(); } public synchronized void waitTwo() { try { Thread.sleep(1000); } catch (Exception e) { } waitOne(); } private class TOne extends Thread { public void run() { System.out.println("tone started"); waitOne(); System.out.println("tone finished"); } } private class TTwo extends Thread { public void run() { System.out.println("ttwo started"); waitTwo(); System.out.println("ttwo finished"); } } public void doo() { TOne t1 = new TOne(); TTwo t2 = new TTwo(); t1.start(); t2.start(); while (t1.isAlive() || t2.isAlive()) { try { Thread.sleep(100); } catch (Exception e) { } } System.out.println("Done"); } public static void main(String[] args) { new TL().doo(); } }