有程序如下:
class StopThread implements Runnable
{
public volatile boolean stop = false; public static void main(String args[]) throws Exception
{
Runnable r = new StopThread();
System.out.println("Starting thread...");
Thread threads = new Thread(r);
threads.start();
} public void run()
{
while (!stop)
{
System.out.println("Thread running...");
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
System.out.println("Thread interrupted...");
}
}
System.out.println("Thread exiting under request...");
}
}我如何在外部正常停止这个程序?
class StopThread implements Runnable
{
public volatile boolean stop = false; public static void main(String args[]) throws Exception
{
Runnable r = new StopThread();
System.out.println("Starting thread...");
Thread threads = new Thread(r);
threads.start();
} public void run()
{
while (!stop)
{
System.out.println("Thread running...");
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
System.out.println("Thread interrupted...");
}
}
System.out.println("Thread exiting under request...");
}
}我如何在外部正常停止这个程序?
Thread threads = new Thread(r);
threads.start();
threads.interrupted(); // 用这个就可以中断那个线程了。
Thread threads = new Thread(r);
threads.start();
threads.interrupted(); // 用这个就可以中断那个线程了。
再不行只能杀进程了