Created
February 16, 2019 09:34
-
-
Save jackblack369/a37dafcf3d4bde1f3722a7b2671cd42a to your computer and use it in GitHub Desktop.
[code-thread] #java
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
class MyThread extends Thread | |
{ | |
@Override | |
public void run() | |
{ | |
while (!Thread.interrupted()) | |
{ | |
System.out.println("I am running...."); | |
} | |
System.out.println("Stopped Running....."); | |
} | |
} | |
public class MainClass | |
{ | |
public static void main(String[] args) | |
{ | |
MyThread thread = new MyThread(); | |
thread.start(); | |
try | |
{ | |
Thread.sleep(100); | |
} | |
catch (InterruptedException e) | |
{ | |
e.printStackTrace(); | |
} | |
//interrupting the thread | |
thread.interrupt(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment