The Java Program: CountThread.java

  1 // CountThread -- From Anuff, page 201
  2 
  3 class CountThread extends Thread {
  4    int maxcount;
  5 
  6    CountThread (int maxcount) {
  7       this.maxcount = maxcount;
  8    }
  9 
 10    public void run () {
 11       for (int count=1; count < maxcount; count++) {
 12          System.out.println ("The count is " + count + ".  Sleeping ...");
 13          try {
 14             sleep(10);
 15             System.out.println ("The count is " + count + ".  Awoke!");
 16          } catch (InterruptedException e) {
 17             System.out.println ("The count is " + count + ".  Sleep interrupted!");
 18             return;
 19          }
 20       }
 21    }
 22 
 23    public static void main (String args[]) {
 24       new CountThread(5).start();
 25    }
 26