Java Thread Test7 - Shared Mem with Main

Main now continues to execute (three threads of execution total).
Note that main is NOT synchronized with the threads.
// Ttest7.java
// it contains a test java program, that defines a class jtest with
// a main function that prints howdy, and creates threads from the
// class Thread7.java
// It passes parameters to the threads, a name and an ID number.
// It has a public static array that is accessible and shared by the main and the threads.
// Notice that the main accessing sharedarray is NOT synchronized with the thread access.

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

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


class Ttest7 {
	public static int sharedarray[] = new int [4]; //static means one copy shared by
						//all the threads - shared memory
						//made public for thread access
	public static void main(String argv[]) {
		System.out.println("Howdy from Ttest7");
  		new Thread7("Thread1", 0); //creates a thread
		new Thread7("Thread2", 1); //creates another thread
		while (true) {
		   System.out.println("     From main: sharedarray[3]= " + sharedarray[3]);
	           try {
                       Thread.sleep(1000);     //milliseconds
                   } catch (InterruptedException e) {
                       return;
		   }

		}
	}
}
//************* second file ******************************************

// Thread7.java
// It is a thread class to be run from Ttest7
// It receives parameters from the parent, a thread name and ID number
// The thread runs forever (until Ctrl-C at keyboard).
// Illustrates communication through shared-memory (static variables with parent)
// Illustrates how to declare and instantiate an array.
// Illustrates concurrency problem: race conditions.
// Illustrates how to use random numbers.
// Solves race conditions with synchronize, to protect the critical section

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

import java.lang.Math;
import java.util.Random;
public class Thread7 extends Thread {
	private int myid;	// private to this thread
	private int count;      // private count of iterations
	private int randwait;   // random amount of sleep time

  	Random randGen;		// a pointer to a Random generator
	private int temp;	// holds sharedarray value temporarily

	Thread7(String name, int me) { //constructor - executed when thread is created with new
	   super(name); //super is part of the Thread class
	   myid=me;     
	   count = 0;   //initialize count
	   randGen = new Random(myid);	//instantiate randGen and seed the sequence
	   start(); // by default calls method "run"
	}

	public void run() {
	   while (true) {
	        count++;
		synchronized(Ttest7.sharedarray) {
		   temp = Ttest7.sharedarray[3];		//all theads access same location
		   randwait = (Math.abs(randGen.nextInt()) % 1000) +1;

		   System.out.println("Howdy from " + Thread.currentThread().getName() + 
		   ",   id=" + myid + "  count is " + count + "  sharedarry[3]=" +
		   Ttest7.sharedarray[3] + " random=" + randwait);

	           try {
                       Thread.sleep(randwait);     //milliseconds
                   } catch (InterruptedException e) {
                       return;
		   }
		   Ttest7.sharedarray[3]=temp+1;		//introduce concurrency problem
		}
	   }	
	}
}