Terminating the the thread by pressing the enter button in this program
import java.io.*;
class MyThread2 extends Thread{
boolean stop=false;
public void run()
{
for(int i=1;i<10000;i++)
{
System.out.println(i);
if(stop) return;
}
}
}
class Main2
{
public static void main(String[]args) throws IOException
{
MyThread2 mt=new MyThread2();
Thread t=new Thread(mt);
t.start();
mt.stop=true;
}
}
0 comments:
Post a Comment