The Java Program: Simple.java

  1 // Simple.java -- Java program illustrating thread creation
  2 // from the Java Tutorial
  3 
  4 class SimpleThread extends Thread {
  5 
  6    public SimpleThread(String name) {
  7       super(name);
  8    }
  9 
 10    public void run() {
 11       for (int i = 0; i < 10; i++) {
 12          System.out.println (i + " " + getName());
 13          try {
 14             sleep((int)(Math.random() * 1000));
 15          } catch (InterruptedException e) {
 16             // do nothing!
 17          }
 18       }
 19       System.out.println ("DONE! " + getName());
 20    }
 21 }
 22 
 23 class Simple {
 24    public static void main (String args[]) {
 25       new SimpleThread("Jamaica").start();
 26       new SimpleThread("Bahamas").start();
 27    }
 28 }