Strumenti Utente

Strumenti Sito


lpr-b-2007-2008:ilthread

<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>

lpr-b-2007-2008/ilthread.txt · Ultima modifica: 19/09/2008 alle 14:08 (11 anni fa) (modifica esterna)