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
|
//Récupération des infos du processeur.
OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
maxThreads = bean.getAvailableProcessors();
log.note("Nombre de threads disponibles: " + maxThreads);
//Lancement initial des threads.
Thread Analysing[] = new Thread[maxThreads];
for(int i = 1; i < maxThreads; ++i){
log.debug("Lancement du thread n°" + i + " avec le bloc n°" + i);
Analysing[i] = new Thread (new Analysing(i, 5, i));
Analysing[i].start();
launched++;
}
int tstop = 0;
boolean onGoing = true;
//Relancement des threads jusqu'a ce que tous les blocs soient analysé
while (onGoing){
for(int i = 1; i < maxThreads; ++i){
if (Analysing[i].getState() == Thread.State.TERMINATED && launched < buffer.lenght()){
log.debug("Relancement du thread n°" + i + " avec le bloc n°" + launched);
Analysing[i] = new Thread (new Analysing(launched, 5, i));
Analysing[i].start();
launched++;
}
// A partir d'ici il y a une erreur mais j'ai la flemme de la régler pour l'instant
else if(launched > buffer.lenght() && Analysing[i].getState() == Thread.State.TERMINATED){
tstop++;
if (tstop == maxThreads){
onGoing = false;
}
}
}
}
log.debug("Taches terminees."); |
Partager