怎么停止一个阻塞线城
第一次不输入,等终止athread,但是实际上它还是活的,还在等待键盘输入,然后第二次输入要两次回车才能取到数据,该怎么把第一个线程彻底杀死,不让用户需要输入两次回车
import java.io.*;
public class Test
{
public static void main(String[] args)
{
AThread a=new AThread();
a.setDaemon(true);
a.start();
try{
Thread.sleep(10000);
a.interrupt();
}catch(Exception er){}
try{ Thread.sleep(10000);}catch(Exception er2){}
System.out.println(a.isAlive());
a=null;
try{ Thread.sleep(10000);}catch(Exception er2){}
a=new AThread();
a.start();
System.out.println("Hello World!");
}
}
class AThread extends Thread
{
public void run() {
try{
System.out.println("start Thread !\n 输入数据");
BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) ) ;
String str = in.readLine() ;
System.out.println("输入数据"+str);
}catch(Exception err){
err.printStackTrace();
}
}
}