如果我有这样的线程:
Thread t = new Thread(myThread);
t.start();
private static Runnable myThread = new Runnable() {
public void run() {
try{
String line=null;
while ((line = eStream.readLine()) != null){
//do something
}
}
catch (Exception e){}
}
};
现在在while循环中发生了什么,有时会readLine()
被挂起,因为它期待来自外部进程的输入。所以在那种情况下,我想做的是设置一个计时器,如果它到期,interrupt this thread t
我t.interrupt();
现在,当我尝试InterruptedException
在 try 块之后捕获时,我收到编译时错误。有人可以告诉我在这种情况下,我怎样才能捕获中断异常?
谢谢