I don't understand why the program uses System.out.println(new GenerateThread()) in main but also in run. What is the difference?
package com.codegym.task.task16.task1623;
/*
Creating threads recursively
*/
public class Solution {
static int count = 15;
static volatile int createdThreadCount;
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));
start();
}
@Override
public String toString() {
return getName() + " created";
}
public void run() {
if (createdThreadCount < count) System.out.println(new GenerateThread());
}
}
}