Created
April 12, 2017 12:03
-
-
Save americanstone/93c8e395357858df82c3ccc5742bf41a to your computer and use it in GitHub Desktop.
When running this code with the line commented, the thread is not deamon, so even if your main method has finished, you'll keep on having the console flooded until you stop it with CTRL+C. That is, the JVM will not exit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Spawner { | |
public static void main(String[] args) { | |
Thread t = new Thread(new Runnable() { | |
public void run() { | |
while (true) { | |
System.out.println("I'm still alive"); | |
} | |
} | |
}); | |
t.start(); | |
// Try uncommenting/commenting this line | |
// t.setDaemon(true); | |
System.out.println("Main thread has finished"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment