What will be the outcome when the following application is executed?
public class Main { public void newThread() { Thread t = new Thread() { public void run() { System.out.println("Going to sleep"); try { sleep(5000);/*from w ww.ja va2s . c o m*/ } catch (InterruptedException e) { } System.out.println("Waking up"); } }; t.start(); try { t.join(); } catch (InterruptedException e) { } System.out.println("All done"); } public static void main(String[] args) { new Main().newThread(); } }
A.
With the call to join()
after the new thread is created and started, the main thread will wait for the new thread to finish its execution before continuing any processing after the call to join()
.