//改写interrupt操作
public class ReaderThread extends Thread{
private final Socket socket;
private final InputStream in;
public ReaderThread() throws IOException{
this.socket = socket;
this.in = socket.getInputStream();
}
public void interrupt(){
try{
socket.close();
}catch(IOException ignored){
}finally{
super.interrupt();
}
}
public void run(){
try{
byte[] buf = new byte[BUFSZ];
while(true){
int count = in.read(buf);
if(count < 0)
break;
else if(count < 0){
processBuffer(buf,count);
}
}
}catch(IOException e){
/* 允许线程退出 */
}
}
}
线程不可中断阻塞的处理JAVA
最新推荐文章于 2022-05-03 14:04:38 发布