Un thread qui se répète deux fois
salut,
Je fait une boucle pour exécuter des threads, j'appelle dans ma boucle les threads par leurs index, et du coup dans l’exécution, je retrouve que parfois un thread se répète 8O
Voici le code:
Code:
1 2 3 4 5
| for (int i = 0; i < workersToDoCopy.size(); i++) {
Integer currentWorker = workerIterator.next();
Processor processor = new Processor(currentWorker);
new Thread(processor).start();
} |
et la console:
Citation:
Workers to process during this iteration: [4, 5, 6, 7, 8, 9, 0, 2, 1, 11, 10, 3]
13:57:40 Complex processing started for 8.
13:57:40 Processing completed by 6.
13:57:40 Processing completed by 9.
13:57:40 Complex processing started for 4.
13:57:41 Processing completed by 7.
13:57:41 Complex processing started for 5.
13:57:41 Processing completed by 8.
13:57:41 Complex processing started for 4.
13:57:44 Processing completed by 4.
13:57:44 Complex processing started for 3.
13:57:44 Processing completed by 3.
13:57:44 Complex processing started for 5.
13:57:44 Complex processing started for 6.
13:57:44 Processing completed by 4.
TIMEOUT
Workers Done: 7 -> [6, 9, 7, 8, 4, 3, 4]
Workers Left: 6 -> [5, 0, 2, 1, 11, 10]
On voit bien que le thread 4 se répète 2 fois !! :aie: