/** * Driver for the ping pong example. * compile with : javac Game.java * and run with : java Game */ import util.MoreOutputStream; public class Game { /** * Main function which starts up a game between alice and * bob. Note on the output how they alternately print PING * and wait. Uncomment the calls to create 'chuck' and see * how the class supports round robin scheduling of three * threads as well. Make sure you change bob's opponent from * alice to chuck to keep the play even. */ public static void main(String args[]) { PingPong table = new PingPong(); Thread alice = new Thread(new Player("bob", table)); Thread bob = new Thread(new Player("alice", table)); Thread chuck = new Thread(new Player("alice", table)); System.out = new java.io.PrintStream(new MoreOutputStream()); alice.setName("alice"); bob.setName("bob"); chuck.setName("chuck"); alice.start(); // alice starts playing bob.start(); // bob starts playing chuck.start(); // chuck starts playing try { // Wait 5 seconds Thread.currentThread().sleep(5000); } catch (InterruptedException e) { } table.hit("DONE"); // cause the players to quit their threads. /* * On Windows you will need this to allow bob and alice to * exit before this thread exits or it will hang. */ try { Thread.currentThread().sleep(100); } catch (InterruptedException e) { } } }