class MyThread implements Runnable { int count; Thread thrd; // Konstruuje nove vlakno MyThread(String name) { thrd = new Thread(this, name); count = 0; thrd.start(); // startuje vlakno } // Začátek exekuce vlakna public void run() { System.out.println(thrd.getName() + " startuje "); try { do { Thread.sleep(500); System.out.println("V potomkovi " + thrd.getName() + ", citac je " + count); count++; } while(count < 5); } catch(InterruptedException exc) { System.out.println(thrd.getName() + " preruseny."); } System.out.println(thrd.getName() + " ukonceny."); } } class VlaknoLepsi { public static void main(String args[]) { System.out.println("Hlavni vlakno startuje"); MyThread mt = new MyThread("potomek"); do { System.out.print("."); try { Thread.sleep(100); } catch(InterruptedException exc) { System.out.println("Hlavni vlakno prerusene."); } } while (mt.count != 5); System.out.println("Hlavni vlakno konci"); } }