1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
public class MathThread extends Thread {
int num;
static Lock veroux4 = new ReentrantLock();
static Condition tousIci = veroux4.newCondition();
static boolean[] lignes;
static int etape;
static int nombre;
static boolean wait=true;
/** Creates a new instance of MathThread */
public MathThread(int num) {
this.num=num;
}
public void run() {
veroux4.lock();
nombre++;
if(nombre==5){
System.out.println("Le processus n° "+num+" débloque les autres processus.");
tousIci.signalAll();
}
else{
try {
System.out.println("Le processus n° " + num + " attend les autre processus.");
tousIci.await();
System.out.println("Le processus n° " + num + " est débloquer.");
} catch (InterruptedException ex) {
Logger.getLogger(MathThread.class.getName()).log(Level.SEVERE, null, ex);
}
}
veroux4.unlock();
}
} |
Partager