在JDK9上运行WildFly16并反复调用java StringReader时,我得到UT010029流是关闭的。
public void export(OutputStream out) throws Exception {
...
while() {
...
csvstream = new StringReader(csvcontent.toString());
try {
while ((iRead = csvstream.read()) != -1) out.write(iRead);
out.flush();
} catch(IOException e) {
validconnection=false;
log.error(e);
e.printStackTrace();
break;
} finally {if (csvstream != null) csvstream.close();}
}错误发生在csvstream.read()上
java.io.IOException: UT010029: Stream is closed
at io.undertow.servlet.spec.ServletOutputStreamImpl.write(ServletOutputStreamImpl.java:137)
at io.undertow.servlet.spec.ServletOutputStreamImpl.write(ServletOutputStreamImpl.java:122)我已经验证了csvstream不为空,但已关闭,并且csvcontent不为空,并且长度为正。有时它会运行所有的迭代没有问题,有时它会出错。
看起来"out“可能是关闭的流。ServletOutputStreamImpl.java中令人不快的行是:
if (anyAreSet(state, FLAG_CLOSED) || servletRequestContext.getOriginalResponse().isTreatAsCommitted()) {
throw UndertowServletMessages.MESSAGES.streamIsClosed();在我的例子中,out是作为参数传入的。主叫方是一个servlet,如下所示:
OutputStream out = response.getOutputStream( );
if (ve!=null) {
try {
ve.export(out);
} catch (Exception e) {
e.printStackTrace();
}
} //if ve!=nullve是一个简单的POJO。
对此任何帮助都将不胜感激!谢谢。
发布于 2021-02-27 23:29:31
如果其他人遇到这个问题--这是通过standalone.xml的wildfly配置解决的: http-listener元素有属性read-timeout和write-timeout。更新版本的wildfly限制了默认值,并且这些属性没有在默认standalone.xml中指定。请参见:
Wildfly模型参考
https://stackoverflow.com/questions/65946971
复制相似问题