Created
February 16, 2016 08:45
-
-
Save skumjava/2f2ceebca1ec32cbbb6a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 DaemonThread { | |
| public static void main(String[] args) { | |
| System.out.println("Entering Main Thread"); | |
| Thread t = new Thread(new Runnable(){ | |
| @Override | |
| public void run() { | |
| for(int i=0; i<5; i++) { | |
| System.out.println("Executing Daemon Thread"); | |
| try { | |
| Thread.sleep(1); | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| }); | |
| t.setDaemon(true); // Thread becomes daemon thread here | |
| t.start(); | |
| System.out.println("Exiting Main Thread"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment