// TestThreadPriority.java: Test thread priorities
//package Chapter13;

public class TestThreadPriority
{
  // Main method
  public static void main(String[] args)
  {
    // Create three threads
    PrintChar printA = new PrintChar('a',200);
    PrintChar printB = new PrintChar('b',200);
    PrintChar printC = new PrintChar('c',200);

    // Set thread priorities
    printA.setPriority(Thread.NORM_PRIORITY);
    printB.setPriority(Thread.NORM_PRIORITY+1);
    printC.setPriority(Thread.NORM_PRIORITY+2);

    // Start threads
    printA.start();
    printB.start();
    printC.start();
  }
}

// The thread class for printing a specified character
// in specified times
class PrintChar extends Thread
{
  private char charToPrint;  // The character to print
  private int times;  // The times to repeat

  // Construct a thread with specified character and number of
  // times to print the character
  public PrintChar(char c, int t)
  {
    charToPrint = c;
    times = t;
  }

  // Override the run() method to tell the system
  // what the thread will do
  public void run()
  {
    for (int i=1; i < times; i++)
      System.out.print(charToPrint);
  }
}