Skip to content

Instantly share code, notes, and snippets.

@jackblack369
Created February 16, 2019 09:34
Show Gist options
  • Save jackblack369/a37dafcf3d4bde1f3722a7b2671cd42a to your computer and use it in GitHub Desktop.
Save jackblack369/a37dafcf3d4bde1f3722a7b2671cd42a to your computer and use it in GitHub Desktop.
[code-thread] #java
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