next up previous contents
Next: L'ordonnanceur Java Up: Les threads Previous: Les threads Java

Un exemple

class PingPong extends Thread { 
  String word;
  int delay;
  PingPong(String whatToSay, int delayTime ) {
    word = whatToSay;
    delay = delayTime;
    }
  public void run() {
    try {
      for (;;) {
        System.out.print(word + " ");
        sleep(delay);
        }
    }
    catch (InterruptedException e) {
      return;
    }
  }
  public static void main(String []argv) {
    new PingPong("ping",33).start();
    new PingPong("PONG",100).start();
    }
}



Alain GRIFFAULT
2002-02-11