public class PingPongTest2{

   public static void showThreads(String msg) {
      Thread[] tlist = new Thread[50];
      int count;
      count = Thread.enumerate(tlist);
      System.out.println(msg + " Number of threads: "+count);
      for (int i=0;i<count;i++) 
        System.out.println("    "+i+": "+tlist[i]);
   }

  public static void main (String[] args){
     PingPong ping;
     PingPong pong;

     showThreads("Start of main");
     ping = new PingPong("ping", 2000, 10);
     showThreads("ping created");
     pong = new PingPong("PONG", 3000, 5);
     showThreads("pong created");
     ping.start();
     pong.start();
     try {
       pong.join();
     } catch(InterruptedException e) {}
     showThreads("pong joined");
     try {
       ping.join();
     } catch(InterruptedException e) {}
     showThreads("ping joined");
  }
}
