spring 我收到池错误超时等待空闲对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20401254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I am getting pool error Timeout waiting for idle object
提问by PSR
<Resource name="jdbc/name" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql:url?autoReconnect=true"/>
I created connection pool using the above statement in Tomcat server.
我在 Tomcat 服务器中使用上述语句创建了连接池。
Some android app is connecting with my application using web service.Through web service i am sending and receiving some data. I am getting the error
一些 android 应用程序正在使用网络服务与我的应用程序连接。通过网络服务,我正在发送和接收一些数据。我收到错误
SQLState: null
[2013-12-05 14:13:06,156]ERROR069688[http-8080-10] - org.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:78) -
Cannot get a connection, pool error Timeout waiting for idle object
I saw Connection Pool Exception: Cannot get a connection, pool error Timeout waiting for idle object.
我看到Connection Pool Exception: Cannot get a connection, pool error Timeout waiting for idle object。
But no clue for me.
但对我来说没有任何线索。
What are the reasons for this.
这是什么原因。
Thanks in advance...
提前致谢...
回答by reblace
This exception is stating that the pool manager cannot produce a viable connection to a waiting requester and the maxWait has passed therefore triggering a timeout. There are several potential causes, but they usually fall into two broad categories:
此异常表明池管理器无法与等待的请求者建立可行的连接,并且 maxWait 已通过,因此触发超时。有几个潜在的原因,但它们通常分为两大类:
The DB is down or unreachable. This could be because you forgot to start it, or it crashed, or the network between you and the DB has stopped working. But basically, the pool has been unable to provide a valid new connection and so the requester has sat waiting for a new connection for longer than the timeout and has given up. This is usually the less likely case cause you usually see other errors when this happens.
The connection pool (which is set to 100 max active) is out of connections. This could be due to high demand volume, or it could be an indication of a connection leak where connections are never returned to the pool and eventually you exceed the max connections limit. This is the more likely cause... usually a connection leak due to not closing db resources when you're done with them.
DB 已关闭或无法访问。这可能是因为你忘记启动它,或者它崩溃了,或者你和数据库之间的网络已经停止工作。但基本上,池无法提供有效的新连接,因此请求者等待新连接的时间超过了超时时间并放弃了。这通常是不太可能的情况,因为发生这种情况时您通常会看到其他错误。
连接池(设置为 100 个最大活动)没有连接。这可能是由于高需求量,或者它可能是连接泄漏的迹象,其中连接永远不会返回到池中,最终您超过了最大连接限制。这是更可能的原因......通常是由于在完成数据库资源后没有关闭数据库资源而导致连接泄漏。
Sometimes 1 and 2 to create this scenario if say the DB encounters an error where queries stop being executed. When that happens, its like a connection leak because new connections go out and block on a query against the DB and are never released. Eventually all the connections are active and the next thread to request a connection will be put in the wait queue because there are no more connections to give out. Since the DB's hosed, you won't see any other exceptions until the first requester who times out in the wait queue. We used to see this occasionally using Oracle UCP when the Oracle DB backend crashed.
如果说数据库遇到查询停止执行的错误,有时 1 和 2 来创建这种情况。当这种情况发生时,它就像一个连接泄漏,因为新连接出去并阻塞对数据库的查询并且永远不会被释放。最终所有连接都处于活动状态,下一个请求连接的线程将被放入等待队列,因为没有更多的连接可以发出。由于数据库已被冲洗,您将不会看到任何其他异常,直到第一个在等待队列中超时的请求者。我们曾经在 Oracle DB 后端崩溃时偶尔使用 Oracle UCP 看到这种情况。
I'd recommend using JConsole to monitor the DB pool sizes when this happens and determine which of the two above categories of causes this error is triggered by. And then, you can try to fix the connection or manipulate the pool size/timeout parameters to accommodate the real demand (you can also manipulate connector parameters in Tomcat to reduce the overall demand on the application). If you're running in Tomcat, you can usually just run JConsole (which is in the JDK bin directory) and attach to the tomcat process and then just look through the JMX console to find where the pool size is found... that usually depends on the data source type (dbcp vs oracle ucp vs etc). Then, you can double click on the field values to plot them so you can track them over time.
我建议在发生这种情况时使用 JConsole 监视数据库池大小,并确定触发此错误的上述两种原因中的哪一种。然后,您可以尝试修复连接或操纵池大小/超时参数以适应实际需求(您也可以在 Tomcat 中操纵连接器参数以减少对应用程序的整体需求)。如果您在 Tomcat 中运行,通常只需运行 JConsole(位于 JDK bin 目录中)并附加到 tomcat 进程,然后只需查看 JMX 控制台以查找池大小的位置...通常取决于数据源类型(dbcp vs oracle ucp vs etc)。然后,您可以双击字段值以绘制它们,以便您可以随时间跟踪它们。
Also, you may need to enable JMX in Tomcat for JConsole JMX monitoring to work.
此外,您可能需要在 Tomcat 中启用 JMX 才能使 JConsole JMX 监控工作。