<code java> package TestIngresso;

public class IlThread extends Thread {

AlternatingProtocol ap = null; 
int order = 0; 
public IlThread(AlternatingProtocol ap, int order) {
	this.ap = ap; 
	this.order = order;
}
public void run() {
	if(order == 0) {
		ap.P();
	}
	while(true) {
		System.out.println(this.getName() + " sbloccato");
		int secs = ((int) (Math.random() * 10.0));
		while(secs > 0) {
			try { 
				Thread.sleep(1000);
			} catch(InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(this.getName() +" "+ secs--);
		}
		ap.V();
		System.out.println(this.getName()+ " in attesa ...");
		ap.P();
	}
}

} <code>