Skip to content

Instantly share code, notes, and snippets.

@skumjava
Created February 16, 2016 08:45
Show Gist options
  • Select an option

  • Save skumjava/2f2ceebca1ec32cbbb6a to your computer and use it in GitHub Desktop.

Select an option

Save skumjava/2f2ceebca1ec32cbbb6a to your computer and use it in GitHub Desktop.
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