import java.util.ArrayList;
import java.util.List;

class AffableThread implements Runnable {
    public void run() {   //Этот метод будет выполнен в побочном потоке
        System.out.println("Привет из побочного потока!"+Thread.currentThread().getName());
    }
}

public class Main {
    static AffableThread mSecondThread;

    public static void main(String[] args) throws java.lang.InterruptedException {
        mSecondThread = new AffableThread();
        List<Thread> threads = new ArrayList<>();
        int i = 0;
        while (i<5) {
            Thread msSecondThread = new Thread(mSecondThread);
            msSecondThread.start();
            threads.add(msSecondThread);
            i++;
        }
        for (Thread t : threads) {
            t.join();
        }
        if ( i== 5){
            System.out.println("Главный поток завершён...");
        }
    }
}
