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() + " ukonceny"); } } class ViceVlaken { 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"); do { System.out.print("."); try { Thread.sleep(100); } catch(InterruptedException exc) { System.out.println("Hlavni vlakno prerusene"); } } while (mt1.count < 3 || mt2.count < 3 || mt3.count < 3); System.out.println("Hlavni vl. konci"); } }