3

我编写了最简单的 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我尝试使用Chrome 浏览器从 java 客户端向这个 servlet 发出 GET 请求。两种情况都设法从 1 MB 到 90 MB 随机下载,然后下载停止,而即使在客户端停止后,java.exeWAS 服务器进程的私有字节继续上升(从 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)

Caused by: java.io.IOException: Async IO operation failed (2), reason: 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 容器出现了问题。

有人可以帮我弄这个吗?

4

0 回答 0