NSY102 1
Concurrence compléments
Notes de cours
Cnam Paris
jean-michel Douin, douin au cnam point fr
19 Mars 2007
NSY102 2
Bibliographie utilisée
premier support +
[SCHM00] Schmidt, D., Stal, M., Rohnert, H., Buschmann, F., Pattern-
oriented
Software Architecture, John Wiley & Sons, 2000.
NSY102 3
Sommaire
java.lang.Thread
Exemples supplémentaires
wait/notify,notifyAll compléments
java.lang.ThreadGroup
Synchronisation, patrons
faible : Producteur/consommateur
forte : Rendez Vous
java.util.concurrent
Patrons selon M.Grand
NSY102 4
Exemple déjà vu
public class T extends Thread {
public void run(){
while(true){
System.out.println("dans " + this + ".run");
}
}
}
public class Exemple {
public static void main(String[] args) {
T t1 = new T(); T t2 = new T(); T t3 = new T();
t1.start(); t2.start(); t3.start();
while(true){
System.out.println("dans Exemple.main");
}
}
}
NSY102 5
Un autre exemple [extrait de Java Threads p17]
import java.awt.*;
class TimerThread extends Thread{
private Component comp;
private int timeDiff;
public TimerThread(Component comp, int timeDiff){
this.comp = comp;
this.timeDiff = timeDiff;
}
public void run(){
while( !isInterrupted()){
try{
comp.repaint(); // déclenchement cyclique
sleep(timeDiff);
}catch(InterruptedException e) {}
}
}
}
1 / 59 100%
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !