I think this is very close to what Thread.join does.
public class Test1 { public static void main(String[] args) throws Exception { Thread t = new Thread(); synchronized (t) { t.start(); while (t.isAlive()) { t.wait(); } } } }
Pay attention to the magic - something wakes up t.wait () - this is because the JVM notifies the Thread object when it completes
source share