Created
March 2, 2019 14:58
-
-
Save Orange168/2ff4c7a90c837f5859d3e2ba581a8e43 to your computer and use it in GitHub Desktop.
[多线程]java不支持中断的多线程处理#多线程#中断
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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