Java Thread Test20 arrays of threads


// Ttest20.java
// it contains a test java program, that defines a class Ttest20 with
// a main function that prints howdy, and creates threads from the
// class Thread20.java

// compile this file with the command "javac Ttest20.java"
// your path must include the bin directory of the jdk

// run the program with "java Ttest20"
// on some systems

public class Ttest20 {

        public static void main(String argv[]) {
		  int i;
	          Thread20 tptr[] = new Thread20[4];
                  System.out.println("Ttest20a");

		  for (i=0;i<2;i++) {
		      tptr[i] = new Thread20();
		  }

                  System.out.println("Ttest20b");
		  for (i=0;i<2;i++) {
		      tptr[i].start();
		  }

                  System.out.println("Ttest20c");
        }
}

//************* second file ******************************************
// this is file Thread20.java
// compile with "javac Thread20.java"

class Thread20 extends Thread {
        private int count = 0;
	public Thread20() {
	   System.out.println("Hi from thread " + getName());
	}
	
        public void run() {
           while (true) {
              count++;
              System.out.println(getName() + "  " + count);
	      try {
	          Thread.sleep(500);
	      } catch (InterruptedException e) {
        	  return;
	      }
	   }
	               
        }
}