Program 19.5: Mixed Priorities

You set a Thread's priority with the setPriority(int priority) method. Program 19.5 sets Chris's priority higher than Mary's whose priority is higher than Franks. It is therefore likely that even though Chris starts last and Frank starts first, Chris will finish before Mary who will finish before Frank.
public class MixedPriorityTest {

  public static void main(String args[]) {
  
    BytePrinter bp1 = new BytePrinter("Frank");
    BytePrinter bp2 = new BytePrinter("Mary");
    BytePrinter bp3 = new BytePrinter("Chris");
    bp1.setPriority(Thread.MIN_PRIORITY);
    bp2.setPriority(Thread.NORM_PRIORITY);
    bp3.setPriority(Thread.MAX_PRIORITY);
    bp1.start();
    bp2.start();
    bp3.start();
  
  }

}

Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
This Chapter
Examples
Home