Created
July 11, 2021 10:11
-
-
Save wkdalsgh192/9ae1ab5e71ded920d7cedf15b05568af 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
Thread newThread = new Thread(() -> { | |
while (true) { | |
System.out.println("Thread : "+ Thread.currentThread().getName()); | |
try { | |
Thread.sleep(2000L); | |
} catch (InterruptedException e) { | |
System.out.println("Exit!"); | |
return; | |
} | |
} | |
}); | |
newThread.start(); | |
// print out main thread | |
System.out.println(Thread.currentThread().getName()); | |
// cause an interruption to a thread to stop | |
Thread.sleep(6000L); | |
newThread.interrupt(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment