Last active
March 17, 2019 14:28
-
-
Save Yatharth0045/5588f8eed2095e522b105bf46c7ba4d1 to your computer and use it in GitHub Desktop.
This programs signifies that the child threads dies if parent thread dies.
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
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