Skip to content

Instantly share code, notes, and snippets.

@wkdalsgh192
Created July 11, 2021 10:11
Show Gist options
  • Save wkdalsgh192/9ae1ab5e71ded920d7cedf15b05568af to your computer and use it in GitHub Desktop.
Save wkdalsgh192/9ae1ab5e71ded920d7cedf15b05568af to your computer and use it in GitHub Desktop.
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