class Priority extends Thread { int count; static boolean stop = false; static String currentName; Priority(String name) { super(name); count = 0; currentName = name; } public void run() { System.out.println(getName() + " start "); do { count++; if(currentName.compareTo(getName()) != 0) { currentName = getName(); System.out.println("Ve " + currentName); } } while(stop == false && count < 50); stop = true; System.out.println("\n" + 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.setPriority(Thread.NORM_PRIORITY+2); mt2.setPriority(Thread.NORM_PRIORITY-2); // start vlaken mt1.start(); mt2.start(); try { mt1.join(); mt2.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); } }