Skip to content

Instantly share code, notes, and snippets.

@Yatharth0045
Last active March 17, 2019 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yatharth0045/5588f8eed2095e522b105bf46c7ba4d1 to your computer and use it in GitHub Desktop.
Save Yatharth0045/5588f8eed2095e522b105bf46c7ba4d1 to your computer and use it in GitHub Desktop.
This programs signifies that the child threads dies if parent thread dies.
class MyThread {
public static void main(String[] args) {
for (int count = 0; count < 10; count++) {
Thread thread = new Thread(()->{
System.out.println("Thread "+Thread.currentThread().getName()+" is going to start");
try{
Thread.sleep(500);
} catch(InterruptedException exception){
exception.getMessage();
}
System.out.println(Thread.currentThread().getName()+" Child Thread is executed");
});
thread.start();
}
System.out.println("Main Thread");
System.exit(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment