Program 19.3: MultiThreadTest

Within the Thread you can access the threadıs name with the getName() method. Program 19.3 runs three BytePrinter Threads in parallel. Program 19.4 is a revised BytePrinter which uses the getName() method to specify which thread is printing the particular line and includes a constructor that sets the name..

public class MultiThreadTest {

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

}

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