Підкажіть, що не так?
Відповідь:
1 created
2 created
4 created
5 created
6 created
3 created
7 created
8 created
9 created
10 created
12 created
11 created
14 created
13 created
15 created
Process finished with exit code 0
package com.javarush.task.task16.task1623;
/*
Рекурсивное создание нитей
*/
public class Solution {
static int count = 15;
static volatile int createdThreadCount;
public static void main(String[] args) {
System.out.println(new GenerateThread());
}
public static class GenerateThread extends Thread {
public GenerateThread() {
super(String.valueOf(++createdThreadCount));
this.start();
}
@Override
public void run() {
while (createdThreadCount < count) {
System.out.println(new GenerateThread());
}
}
@Override
public String toString() {
return getName() + " created";
}
}
}