/* Three independent threads. The third thread has the
* highest priority and should finish first.
*/
public class TestPriority {
    public static void main(String args[]) {
        // Create threads
        PrintChar printA = new PrintChar('a', 200);
        PrintChar printB = new PrintChar('b', 200);
        PrintNum print100 = new PrintNum(200);

        // Set priority on printA and printB to min
        printA.setPriority(Thread.MIN_PRIORITY);
        printB.setPriority(Thread.MIN_PRIORITY);

        // Set priority on print100 to the max
        print100.setPriority(Thread.MAX_PRIORITY);
        
        printA.start();
        printB.start();
        print100.start();
    } 
} 

class PrintChar extends Thread {
    private char charToPrint; // the character to print
    private int times; // The times to repeat

    public PrintChar(char c, int t) {
        charToPrint = c;
        times = t;
    } 
    
    public void run() {
        for (int i=0; i<=times; i++) {
            System.out.print(" " + charToPrint);
        }
    }
} 

class PrintNum extends Thread {
    private int lastNum; // the last number to print

    public PrintNum(int n) {
        lastNum = n;
    } 

    public void run() {
        int result = -1;
        for (int i=0; i<=lastNum; i++) {
            result++;
            System.out.print(" " + i);
        }
    } 
} 

