二、数据库连接不够用
导致数据库连接不够用的原因主要有: ①某些程序占用connection时间过长,如果多个用户同时使用这些程序,则会导致连接不够用。 ②线程死锁,无法释放connection。 1、诊断方法 ①监控参数:Waiting For Connection High Count [domain_name]-> Enviroment -> Servers -> [Server] -> Monitoring -> JDBC查看参数:Waiting For Connection High Count 如果没有此参数,手工添加进来,该参数表示在没有可用连接的情况下,应用程序等待连接的最大个数。调整后的连接池最大值 = 调整前的连接池最大值 + Waiting For Connection High Count。一般来说,数据库连接池的大小与最佳并发用户数相当。 ②在Server Log中,明确抛出下列异常: java.sql.SQLException: Internal error: Cannot obtain XAConnection weblogic.common.resourcepool.ResourceLimitException: No resources currently available in pool BankConnectionPool to allocate to applications, please increase the size of the pool and retry.. at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist(DataSource.java:1493) at weblogic.jdbc.jta.DataSource.getConnection(DataSource.java:455) at weblogic.jdbc.jta.DataSource.connect(DataSource.java:410) at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:344) at troubleshooting.servlets.JdbcConnections.service(JdbcConnections.java:80) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1077) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:7047) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3902) at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183) 如果此时观察connection的监控,会发现所有connection 都是Active,而且还有大量请求等待connection。 2、解决方法 ①提高Maximum Capacity数量,该值一般略大于峰值情况下的数据库连接数。Services > JDBC > Connection Pools > BankConnectionPool > Configuration > Connections ②重点检查synchronize代码段和涉及数据库锁的代码。如果有必要,可以查看thread dump,看看线程在忙什么和等什么。 三、数据库连接使用超时 此类问题一般是由于某些数据库操作时间比较长,超过了Inactive connection timeout的设置。 1、诊断方法 在Server Log中,明确有下列提示,并且在提示后抛出应用异常: Forcibly releasing inactive resource "weblogic.jdbc.common.internal.ConnectionEnv@132967d" back into the pool BankConnectionPool".这里无法列出应用异常,因为每个应用都不一样,不过很有可能会抛出空指针异常,因为Connection被强制放回池中了,继续使用一个空对象会抛出该异常。 2、解决方法 在高级参数中,提高Inactive connection timeout数量。 Services > JDBC > Connection Pools > BankConnectionPool > Configuration > Connections 四、事务超时 此类问题一般是由于某些数据库操作时间比较长,超过了JTA Timeout Seconds的设置。 1、诊断方法 在Server Log中,明确抛出异常: weblogic.transaction.internal.TimedOutException: Transaction timed out after 300 seconds 2、解决方法 提高Services > JTA Configuration > Timeout Seconds数量。 注意这个参数应该小于Inactive connection timeout的值,因为事务必须在连接超时前完成。如果想分析究竟是哪些SQL语句导致事务超时,可以打开日志AdminServer > Logging > JDBC,选中Enable JDBC Logging,并设置JDBC Log File Name。