Skip to content

Instantly share code, notes, and snippets.

@Orange168
Created March 2, 2019 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Orange168/2ff4c7a90c837f5859d3e2ba581a8e43 to your computer and use it in GitHub Desktop.
Save Orange168/2ff4c7a90c837f5859d3e2ba581a8e43 to your computer and use it in GitHub Desktop.
[多线程]java不支持中断的多线程处理#多线程#中断
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
public class Test32 extends Thread {
public static final int BUF_SIZE = 512;
Socket socket;
InputStream in;
public Test32(Socket socket) throws IOException {
this.socket = socket;
this.in = socket.getInputStream();
}
@Override
public void interrupt() {
try {
socket.close();
} catch (IOException e) {
} finally {
super.interrupt();
}
}
@Override
public void run() {
try {
byte[] buf = new byte[BUF_SIZE];
while (true) {
int count = in.read(buf);
if (count < 0) {
break;
} else if (count > 0) {
}
}
} catch (IOException e) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment