带有球衣的嵌入式 tomcat 上的 java.net.SocketTimeoutException

Posted

技术标签:

【中文标题】带有球衣的嵌入式 tomcat 上的 java.net.SocketTimeoutException【英文标题】:java.net.SocketTimeoutException on embedded tomcat with jersey 【发布时间】:2014-02-28 07:08:10 【问题描述】:

我的服务器应用程序使用带有 Jersey 的嵌入式 tomcat。 我不时收到以下错误:

    02-03-2014 10:06:05 [com.sun.jersey.spi.container.ContainerResponse] [http-nio-8243-exec-4] [ERROR] - The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.net.SocketTimeoutException
    at org.apache.tomcat.util.net.NioBlockingSelector.read(NioBlockingSelector.java:191)
    at org.apache.tomcat.util.net.NioselectorPool.read(NioSelectorPool.java:246)
    at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:227)
    at org.apache.coyote.http11.InternalNioInputBuffer.readSocket(InternalNioInputBuffer.java:419)
    at org.apache.coyote.http11.InternalNioInputBuffer.fill(InternalNioInputBuffer.java:789)
    at org.apache.coyote.http11.InternalNioInputBuffer$SocketInputBuffer.doRead(InternalNioInputBuffer.java:814)
    at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:124)
    at org.apache.coyote.http11.AbstractInputBuffer.doRead(AbstractInputBuffer.java:346)
    at org.apache.coyote.Request.doRead(Request.java:422)
    at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:290)
    at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:449)
    at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:315)
    at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:200)
    at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
    at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
    at sun.nio.cs.StreamDecoder.read(Unknown Source)
    at java.io.InputStreamReader.read(Unknown Source)
    at java.io.Reader.read(Unknown Source)
    at com.google.common.io.CharStreams.copy(CharStreams.java:202)
    at com.google.common.io.CharStreams.toStringBuilder(CharStreams.java:248)
    at com.google.common.io.CharStreams.toString(CharStreams.java:222)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$VoidOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:167)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

对于正在读取输入流的资源(不是那么大,~18K)。 我想知道是否有任何配置可以更改,这将使我的应用程序在读取输入流时等待更多时间。 org.apache.catalina.connector.Connector#setAsyncTimeout 是否与我遇到的问题有关?

谢谢

【问题讨论】:

【参考方案1】:

我可以通过扩大 Tomcat 的读取超时来阻止这些错误,如下所示:

org.apache.catalina.connector.Connector#setProperty

例如:

httpConnector.setProperty("soTimeout", "50000");

【讨论】:

以上是关于带有球衣的嵌入式 tomcat 上的 java.net.SocketTimeoutException的主要内容,如果未能解决你的问题,请参考以下文章

部署在 Tomcat 上的 Spring Boot Rest API 提供 404 但独立工作一切正常

带有嵌入式 Tomcat 的 Jndi Mongodb Spring Boot,[重复]

带有嵌入式 Tomcat 的 Spring Boot 忽略了方法角色

带有嵌入式或独立 tomcat 的 Java docker 容器?

如何在带有嵌入式 tomcat 的 Spring Boot App 中设置域名

使用带有嵌入式 Tomcat 的 Spring Boot Weblfux