Does the main thread get terminated after returning from main(), even after spawning one or more threads?

Alex Chaffee

Yes. You can determine this by running the following program and doing a thread dump:

public class mainthread extends Thread
    public static void main(String[] args)
        mainthread t1 = new mainthread();
        mainthread t2 = new mainthread();

     public void run()
            // do something
You will notice there is no thread named "main" (since by the time you press CTRL-BREAK or CTRL- it has exited).
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.