Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.