简体   繁体   English

Tomcat连接池,空闲连接和连接创建

[英]Tomcat connection pooling,idle connections,and connection creation

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. 我在Web应用程序中遇到以下问题。当我将服务器打开一段时间(例如24小时)时,我的应用程序停止工作。 I am using tomcat 7 and Connection pooling.My Database is MySQL. 我正在使用tomcat 7和连接池。我的数据库是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. //如果我从MYSQL Admin中手动关闭了所有活动连接,请编辑此错误再次出现。

There are background connections. 有后台连接。

How do you define your pool? 您如何定义您的游泳池?

Here are some useful options. 以下是一些有用的选项。

minEvictableIdleTimeMillis="60000"maxActive="100" minIdle="10" maxIdle="50" maxWait="10000"
    removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"

And add in the url the autoReconnect=true 并在URL中添加autoReconnect=true

url="jdbc:mysql://localhost:3306/db?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM