// in PCThread.java

public class PCThread extends Thread {
    private String myName;	// string identifier
    private SharedN nobj;	// reference to shared object

    public PCThread(String whoami, SharedN nobjarg) {
	myName = whoami;
	nobj = nobjarg;
    }

    public void run() {
	int i;
	int loopcnt = 5;

	if (myName.equals("P")) {
	    // producer thread
	    for (i=0; i<loopcnt; i++) {
		nobj.IncrementN();
	    }
	}
	else {
	    // consumer thread
	    for (i=0; i<loopcnt; i++) {
		System.out.println("n is " + nobj.ReadN());
	    }
	}
    }
}

