PPL (201-1289101)

Multithreading in Java

Just the source Back to Course Home Page


public class CountThread extends Thread {

  private int from;
  private int to;

  public static void main(String[] args) {
    for (int i = 0; i < 5; i++) {
      Thread t = new CountThread(i*10, (i+1)*10);
      t.start();
    }
  }

  public CountThread(int from, int to) {
    this.from = from;
    this.to = to;
  }

  public void run() {
    for (int i = from; i < to; i++) {
      System.out.println("i = "+i);
      yield();
    }
  }
}


Last modified May 27th, 1997 Michael Elhadad