阻塞线程怎么回收
拍码屁 2017-01-19 02:41:19 如下的简单代码,线程中的while循环体有一BlockingQueue的take方法一直阻塞,本应该通过一个bool值可以结束循环,但问题是它会阻塞,有什么办法可以解决吗? 我用interupt结束的话,会catch到异常。
private class TestThread extends Thread{
private boolean isTesting;
public void stopRunning(){
isTesting=false;
}
@Override
public void run() {
isTesting=true;
while(isTesting){
try{
String str=(String)testQueue.take();
//do something
}catch (Exception e){
}
}
}
}