我编写了可能的最简单的Servlet,用于将数据流(在测试用例中为14GB文本文件)提供给客户端:
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("application/octet-stream");
resp.setContentLength(-1);
InputStream is = null;
try {
OutputStream os = resp.getOutputStream();
int unitsTransferred = -1;
byte[] buf = new byte[65536];
is = new FileInputStream("D:/largetext2.txt");
while ((unitsTransferred = is.read(buf)) != -1) {
os.write(buf, 0, unitsTransferred);
//os.flush();
}
} catch (Throwable e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
resp.getOutputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
因此,您只需发出一个简单的get请求。我尝试使用URLConnection
从Java客户端和Chrome浏览器向此Servlet发出GET请求。两种情况都设法从1 MB随机下载到90 MB,然后下载停止,而即使客户端已停止,WAS服务器java.exe
进程的专用字节仍在增加(从300 MB到950 MB)。然后服务器吐出以下堆栈跟踪:
com.ibm.wsspi.webcontainer.ClosedConnectionException: OutputStream encountered error during write
at com.ibm.ws.webcontainer.channel.WCCByteBufferOutputStream.write(WCCByteBufferOutputStream.java:106)
at com.ibm.ws.webcontainer.srt.SRTOutputStream.write(SRTOutputStream.java:97)
at com.ibm.wsspi.webcontainer.util.BufferedServletOutputStream.writeOut(BufferedServletOutputStream.java:569)
at com.ibm.wsspi.webcontainer.util.BufferedServletOutputStream.write(BufferedServletOutputStream.java:374)
at si.test.kryo.MyServlet.doGet(MyServlet.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1663)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:939)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
由:java.io.IOException引起:异步IO操作失败(2),原因:RC:64指定的网络名称不再可用。
at com.ibm.io.async.AsyncLibrary$IOExceptionCache.<init>(AsyncLibrary.java:891)
at com.ibm.io.async.AsyncLibrary$IOExceptionCache.get(AsyncLibrary.java:904)
at com.ibm.io.async.AsyncLibrary.getIOException(AsyncLibrary.java:918)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:213)
... 3 more
Java客户端只是在读取调用中处于阻塞状态,而Chrome使下载保持活动状态,而忽略了服务器中止整个过程的事实。因此,要么发生一些奇怪的超时,要么IBM servlet容器出现问题。
有人可以帮我吗?