我们正在使用tomcat servlet容器和Jersey作为RESTful服务引擎开发Web应用程序。该应用程序部署在两个tomcat节点上,通过前面的单个apache webserver和mod_proxy作为负载均衡器进行访问。
如果系统负载中等(数千名用户查询应用程序),catalina.out日志文件中有时会出现以下错误,我们无法理解。处理器负载< 20%,内存几乎是免费的。如果有人能指出我们在哪里寻找问题的正确方向,那就太好了。非常感谢!错误日志出现了:
3131392:27.Apr 17:20:05.827 ERROR ContainerResponse - The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
3131393-java.io.IOException
3131394- at org.apache.jk.common.JkInputStream.receive(JkInputStream.java:205)
3131395- at org.apache.jk.common.JkInputStream.doRead(JkInputStream.java:179)
3131396- at org.apache.coyote.Request.doRead(Request.java:428)
3131397- at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:304)
3131398- at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:405)
3131399- at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:327)
3131400- at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:162)
3131401- at com.sun.jersey.core.util.ReaderWriter.writeTo(ReaderWriter.java:114)
3131402- at com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.writeTo(AbstractMessageReaderWriterProvider.java:76)
3131403- at com.sun.jersey.core.impl.provider.entity.ByteArrayProvider.readFrom(ByteArrayProvider.java:79)
3131404- at com.sun.jersey.core.impl.provider.entity.ByteArrayProvider.readFrom(ByteArrayProvider.java:59)
3131405- at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:456)
3131406- at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
3131407- at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
3131408- at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:138)
3131409- at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
3131410- at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:71)
3131411- at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:280)
3131412- at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
3131413- at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
3131414- at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
3131415- at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
3131416- at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1341)
3131417- at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1273)
3131418- at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1223)
3131419- at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1213)
3131420- at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
3131421- at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
3131422- at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
答案 0 :(得分:1)
我有同样的例外。客户端启动请求但(可能是连接速度慢或断开连接)未完成请求。
您可以避免使用此异常映射程序接收错误日志:
import java.net.SocketTimeoutException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Provider
public class SocketTimeoutExceptionMapper implements ExceptionMapper<SocketTimeoutException> {
public Response toResponse(SocketTimeoutException e) {
Logger logger = LoggerFactory.getLogger(this.getClass());
logger.debug("Read timed out.");
return Response.status(Status.BAD_REQUEST).build();
}
}