The program creates thread t0 which spawns thread t1 and subsequently threads t2 and t3 are created.After the execution of thread t3
and the application never returns to the other threads spawned earlier(t0,t1,t2) and they are left stuck.
Why are the threads t0
, t1
, and t2
suspended?
public class Cult extends Thread
{
private String[] names = {"t1", "t2", "t3"};
static int count = 0;
public void run()
{
for(int i = 0; i < 100; i++)
{
if(i == 5 && count < 3)
{
Thread t = new Cult(names[count++]);
t.start();
try{
Thread.currentThread().join();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
System.out.print(Thread.currentThread().getName() + " ");
}
}
public static void main(String[] a`)
{
new Cult("t0").start();
}
}