Source of Counter2.java


  1: public class Counter2 implements Runnable {
  2: 
  3:     protected int count;
  4:     protected int inc;
  5:     protected int delay;
  6: 
  7:     public Counter2(int init, int inc, int delay) {
  8:         this.count = init;
  9:         this.inc = inc;
 10:         this.delay = delay;
 11:     }
 12: 
 13:     public void run() {
 14:         try {
 15:             for (;;) {
 16:                 System.out.print(count + " ");
 17:                 count += inc;
 18:                 Thread.sleep(delay);
 19:             }
 20:         } catch (InterruptedException e) {}
 21:     }
 22: 
 23:     public static void main(String[] args) {
 24:         new Thread(new Counter2(0, 1, 33)).start();
 25:         new Thread(new Counter2(0, -1, 100)).start();
 26:     }
 27: }