class MyThread implements Runnable { int count; Thread thrd; MyThread(String name) { thrd = new Thread(this, name); count = 0; thrd.start(); // start } public void run() { System.out.println(thrd.getName() + " startuje"); try { do { Thread.sleep(500); System.out.println("Ve " + thrd.getName() + ", citac je " + count); count++; } while(count < 3); } catch(InterruptedException exc) { System.out.println(thrd.getName() + " preruseny"); } System.out.println(thrd.getName() + " konci"); } } class Join { public static void main(String args[]) { System.out.println("Hlavni vlakno startuje"); MyThread mt1 = new MyThread("potomek1"); MyThread mt2 = new MyThread("potomek2"); MyThread mt3 = new MyThread("potomek3"); try { mt1.thrd.join(); System.out.println("potomek1 joined."); mt2.thrd.join(); System.out.println("potomek2 joined."); mt3.thrd.join(); System.out.println("potomek3 joined."); } catch(InterruptedException exc) { System.out.println("Hlavni vlakno prerusene"); } System.out.println("Hlavni vl. konci"); } }