I think it's about thread racing
The program displayed too much data on the console (on the screen).
but I don't know how to avoid it
package pl.codegym.task.task16.task1623;
/*
Rekurencyjne tworzenie wątków
*/
import java.sql.SQLOutput;
public class Solution {
static int count = 15;
static volatile int createdThreadCount = 0;
public static void main(String[] args) throws InterruptedException {
System.out.println(new GenerateThread());
}
public static class GenerateThread extends Thread {
public GenerateThread() {
super(String.valueOf(++createdThreadCount));
this.start();
}
@Override
public String toString() {
return getName() + " utworzony";
}
@Override
public void run() {
while (true)
{
if(createdThreadCount < count)
{
System.out.println(new GenerateThread());
}else return;
}
}
}
}