Why does a thread outlive the main method in Java?

Because that’s how it works. The program exits when System.exit() is called, or when the last non-daemon thread stops running.

And it makes sense. Without this rule, every Java program consisting in just spawning a GUI, for example, would have to wait() infinitely to avoid the program from exiting immediately.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)