Tomcat连接池,空闲连接和连接创建 [英] Tomcat connection pooling,idle connections,and connection creation

查看:451
本文介绍了Tomcat连接池,空闲连接和连接创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Web应用程序中遇到以下问题.当我将服务器打开一段时间(例如24小时)时,我的应用程序停止工作. 我正在使用tomcat 7和连接池.我的数据库是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.

我遇到以下异常:

  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.......

///如果我从MYSQL Admin中手动关闭所有活动连接,则再次出现此错误.

//Edit if i manualy close all active connections from MYSQL Admin this error appears again.

推荐答案

存在后台连接.

您如何定义游泳池?

以下是一些有用的选项.

Here are some useful options.

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

并在URL中添加autoReconnect=true

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

这篇关于Tomcat连接池,空闲连接和连接创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆