class Priority implements Runnable { int count; Thread thrd; static boolean stop = false; static String currentName; Priority(String name) { thrd = new Thread(this, name); count = 0; currentName = name; } public void run() { System.out.println(thrd.getName() + " start "); do { count++; if(currentName.compareTo(thrd.getName()) != 0) { currentName = thrd.getName(); System.out.println("Ve " + currentName); } } while(stop == false && count < 500); stop = true; System.out.println("\n" + thrd.getName() + " konci"); } } class Priorita { public static void main(String args[]) { Priority mt1 = new Priority("Vysoka Priorita"); Priority mt2 = new Priority("Nizka Priorita"); // nastaveni priorit mt1.thrd.setPriority(Thread.NORM_PRIORITY+2); mt2.thrd.setPriority(Thread.NORM_PRIORITY-2); // start vlaken mt1.thrd.start(); mt2.thrd.start(); try { mt1.thrd.join(); mt2.thrd.join(); } catch(InterruptedException exc) { System.out.println("Hlavni vlakno konci"); } System.out.println("Vlakno s velkou prioritou nacitalo " + mt1.count); System.out.println("Vlakno s malou prioritou nacitalo " + mt2.count); } }