Pourquoi faire une synchronisation sur type primitif
Bonjour,
Dans la classe Thread j'ai vu ce code et je ne comprends pas pourquoi il y a besoin de synchroniser l'incrémentation d'un type primitif ?
Code:
1 2 3 4 5 6
| /* For autonumbering anonymous threads. */
private static int threadInitNumber;
private static synchronized int nextThreadNum() {
return threadInitNumber++;
} |
et dans le constructeur
Code:
1 2 3
| public Thread(Runnable target) {
init(null, target, "Thread-" + nextThreadNum(), 0);
} |
Qu'est-ce que j'ai oublié de savoir ? ou pas compris ?
Merci à tous et à toutes pour vos réponses