restful api总是处于挂起状态,tomcat发生了excpetion

时间:2017-03-05 06:45:29

标签: java tomcat jersey

我有一个Web应用程序,但我遇到了一个问题。该请求有时总是处于待处理状态,但在其他时间它可以正常工作。这是意外,如下图所示: enter image description here

Tomcat在“挂起状态”发生后将不再工作,然后我需要重启tomcat,一切正常。我可以在日志文件中找到异常:catalina.2017-03-05.loglocalhost.2017-03-05.log在档案catalina.2017-03-05.log中:

    05-Mar-2017 13:29:55.187 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [EducationCloud-Restful] is still processing a request that has yet to finish. This is very likely to create a memory leak. You can control the time allowed for requests to finish by using the unloadDelay attribute of the standard Context implementation. Stack trace of request processing thread:
sun.misc.Unsafe.park(Native Method)
(...)
05-Mar-2017 13:29:55.254 SEVERE [http-nio-8080-exec-10] org.apache.coyote.http11.Http11Processor.service Error processing request
java.lang.NullPointerException
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:389)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

05-Mar-2017 13:29:55.274 SEVERE [http-nio-8080-exec-10] org.apache.coyote.http11.Http11Processor.endRequest Error finishing response
java.lang.NullPointerException
at org.apache.coyote.http11.Http11OutputBuffer.commit(Http11OutputBuffer.java:351)
at org.apache.coyote.http11.Http11Processor.action(Http11Processor.java:658)
at org.apache.coyote.http11.Http11Processor.endRequest(Http11Processor.java:1786)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1149)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

在文件`localhost.2017-03-05.log'中:

05-Mar-2017 13:29:55.253 SEVERE [http-nio-8080-exec-10] org.apache.catalina.core.StandardHostValve.invoke Exception Processing null
java.lang.NullPointerException
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:236)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

谁能帮我告诉我发生了什么事?非常感谢你!

相关: Tomcat v8.5.4

1 个答案:

答案 0 :(得分:1)

我已经解决了这个问题,原因是来自dbcp2,它的默认最大连接数是8,所以当连接达到8时,所有请求都将处于挂起状态。解决这个问题的方法是我们可以设置最大值当它变得无用时,总计并删除连接,如下所示:

BasicDataSource dataSource = new BasicDataSource()
dataSource.setMaxTotal(-1);  
dataSource.setRemoveAbandonedOnBorrow(true);
dataSource.setRemoveAbandonedTimeout(5); 

负数(-1)表示无限制,“5”表示5秒。