/****************************************************************** * @(#) PingPong.java 1.0 * * Copyright (c) 2003 John Miller * All Right Reserved *----------------------------------------------------------------- * Permission to use, copy, modify and distribute this software and * its documentation without fee is hereby granted provided that * this copyright notice appears in all copies. * WE MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WE SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY ANY USER AS A RESULT OF USING, * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. *----------------------------------------------------------------- * * @version 1.0, 19 Feb 2003 * @author John Miller */ import static java.lang.System.*; /****************************************************************** * The PingPong class tests threads. */ public class PingPong //extends Thread implements Runnable { private String word; private int delay; /************************************************************** * Construct a ping or pong object. */ public PingPong (String whatToSay, int delayTime) { word = whatToSay; delay = delayTime; } // PingPong /************************************************************** * Run method for the ping/pong object. */ public void run () { for ( ; ; ) { out.println (word); try { //sleep (delay); Thread.sleep (delay); } catch (InterruptedException ex) { return; } // try } // for } // run /************************************************************** * Main method for invoking the application. * @param args Command-line arguments */ public static void main (String [] args) { //new PingPong ("ping", 33).start (); //new PingPong ("PONG", 100).start (); new Thread (new PingPong ("ping", 333)).start (); new Thread (new PingPong ("PONG", 1000)).start (); } // main } // PingPong class