Tomcat连接池、空闲连接和连接创建
我在 Web 应用程序中遇到以下问题。当我将服务器打开一段时间(例如 24 小时)时,我的应用程序将停止工作。 我正在使用 tomcat 7 和连接池。我的数据库是 MySQL。
我收到以下异常:
Communication link failure: java.io.EOFException, underlying cause: null ** BEGIN NESTED EXCEPTION ** java.io.EOFException STACKTRACE: java.io.EOFException at
com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1394) at
com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1538) at
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1929) at
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167) at
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278) at
com.mysql.jdbc.Connection.execSQL(Connection.java:2251) at
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586) at
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStat
ement.java:96) at
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStat
ement.java:96) at configuration.Login.doPost(Login.java:104) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.jav
a:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563) at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:403) at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:301) at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java
:162) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java
:140) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at
java.lang.Thread.run(Thread.java:662) ** END NESTED EXCEPTION **
我发现当池连接由于某种原因在一段时间后被关闭(可能是由于时间限制或其他原因)时,会发生此错误。 我的问题是,当池中没有连接时,连接池不应该创建新连接?该错误不是由流量引起的,因为目前没有人使用该应用程序。我该如何修复此错误?当应用程序运行时部署后我开始使用该应用程序,正在创建池连接。这些连接是空闲的?有没有办法这些连接不会被关闭?但是如果我能做到这一点,我不会浪费服务器上其他应用程序的连接吗?
另外,如果我在创建新连接一段时间后继续尝试使用该应用程序并且应用程序开始工作。但这不正常......
//编辑如果我手动关闭来自 MYSQL 管理的所有活动连接此错误再次出现。
I have the following problem in a web application.When i leave the server on for some period for example 24 hours my app stops working.
I am using tomcat 7 and Connection pooling.My Database is MySQL.
I am getting the following exception:
Communication link failure: java.io.EOFException, underlying cause: null ** BEGIN NESTED EXCEPTION ** java.io.EOFException STACKTRACE: java.io.EOFException at
com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1394) at
com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1538) at
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1929) at
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167) at
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278) at
com.mysql.jdbc.Connection.execSQL(Connection.java:2251) at
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586) at
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStat
ement.java:96) at
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStat
ement.java:96) at configuration.Login.doPost(Login.java:104) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:641) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.jav
a:304) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563) at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:403) at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:301) at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java
:162) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java
:140) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at
java.lang.Thread.run(Thread.java:662) ** END NESTED EXCEPTION **
I find out that this error occurred when the pooled connections for some reason after some period of time have been closed maybe due to time limit or something.
My question is that connection pool shouldn't have created new connections when there are no connections into the pool ?The error is not caused by traffic because no one uses the application at the moment.How can I fix this error ?When the app is deployed I start using the app,pooled connections are being created.These connections are idle?Is there a way these connections wont be closed?But if i can do that don't I waste connections from other applications on the server?
Also if I keep trying to use the application after some time new connections are created and the app starts working.But this isn't normal.......
//Edit if i manualy close all active connections from MYSQL Admin this error appears again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有后台联系。
你如何定义你的池?
这里有一些有用的选项。
并在 url 中添加
autoReconnect=true
There are background connections.
How do you define your pool?
Here are some useful options.
And add in the url the
autoReconnect=true