我正在通过我的代码从X服务下载一个文件。下载的文件写在文件系统上。我所面临的问题是,我的例子被卡住了,没有进一步的工作去处理。在线程转储中,我看到大多数线程处于IN_NATIVE状态。
你能帮我找出问题所在吗?
Thread 25493: (state = IN_NATIVE)
- java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[], int, int, int) @bci=0 (Compiled frame; information may be imprecise)
- java.net.SocketInputStream.read(byte[], int, int, int) @bci=87, line=152 (Compiled frame)
- java.net.SocketInputStream.read(byte[], int, int) @bci=11, line=122 (Compiled frame)
- sun.security.ssl.InputRecord.readFully(java.io.InputStream, byte[], int, int) @bci=21, line=442 (Compiled frame)
- sun.security.ssl.InputRecord.read(java.io.InputStream, java.io.OutputStream) @bci=32, line=480 (Interpreted frame)
- sun.security.ssl.SSLSocketImpl.readRecord(sun.security.ssl.InputRecord, boolean) @bci=44, line=927 (Interpreted frame)
- sun.security.ssl.SSLSocketImpl.readDataRecord(sun.security.ssl.InputRecord) @bci=15, line=884 (Interpreted frame)
- sun.security.ssl.AppInputStream.read(byte[], int, int) @bci=72, line=102 (Interpreted frame)
- org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer() @bci=71, line=160 (Compiled frame)
- org.apache.http.impl.io.SocketInputBuffer.fillBuffer() @bci=1, line=84 (Compiled frame)
- org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(org.apache.http.util.CharArrayBuffer) @bci=130, line=273 (Compiled frame)
- org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(org.apache.http.io.SessionInputBuffer) @bci=16, line=140 (Compiled frame)
- org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(org.apache.http.io.SessionInputBuffer) @bci=2, line=57 (Compiled frame)
- org.apache.http.impl.io.AbstractMessageParser.parse() @bci=38, line=260 (Compiled frame)
- org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader() @bci=8, line=283 (Compiled frame)
- org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader() @bci=1, line=251 (Compiled frame)
- org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader() @bci=6, line=197 (Compiled frame)
- org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(org.apache.http.HttpRequest, org.apache.http.HttpClientConnection, org.apache.http.protocol.HttpContext) @bci=41, line=271 (Compiled frame)下面是处理来自X服务的imputstream的代码
public void handleResponse(Response response, InputStream responseStream) throws IOException {
FileOutputStream fos = null;
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
try {
if (response != null && responseStream != null) {
bis = new java.io.BufferedInputStream(responseStream);
//code writing to disk
}
}
catch (IOException e) {
log.error("IOException while writing file " + fileName + " to disk ", e);
}
catch (Exception e) {
log.error("IOException while writing file " + fileName + " to disk ", e);
}
finally {
if (bos != null) {
bos.close();
}
if (fos != null) {
fos.close();
}
if (bis != null) {
bis.close();
}
}
}发布于 2015-03-11 21:28:36
流正在等待来自服务的更多数据。也许服务没有正确地关闭连接,或者您无法检测到流已经结束(读取字节直到它发送-1)。
https://stackoverflow.com/questions/28996081
复制相似问题