在我的Stand One Java应用程序中,我们使用基于Hibernate JPA的Pooled DataSource连接Oracle数据库。我们间歇性地得到以下异常。但是在重试时,它通常会成功创建连接池。此外,其他也访问相同数据库服务器的服务可以成功创建连接池。
如何解决这个问题?
是否有任何连接泄漏以及如何诊断?
线程中的异常" main" com.xyz.abc.inf.console.ConsoleException:javax.persistence.PersistenceException:org.hibernate.exception.GenericJDBCException:无法打开连接
at com.xyz.abc.inf.console.service.GatewayService.postStart(GatewayService.java:104)
at com.xyz.abc.inf.console.service.AbstractLaunchableService.start(AbstractLaunchableService.java:205)
at com.xyz.abc.inf.console.ConsoleLauncher.main(ConsoleLauncher.java:85)
引起:javax.persistence.PersistenceException:org.hibernate.exception.GenericJDBCException:无法打开连接
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:273)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:311)
at $Proxy102.getResultList(Unknown Source)
at com.nrift.finch.inf.domain.repository.RepositoryBase.query(RepositoryBase.java:139)
at com.xyz.abc.inf.domain.dao.jpa.impl.ServiceRouteParticipantDaoImpl.findByServiceId(ServiceRouteParticipantDaoImpl.java:55)
at com.xyz.abc.inf.service.impl.RouteResolverServiceImpl.getRouteByService(RouteResolverServiceImpl.java:21)
at com.xyz.abc.inf.console.service.GatewayService.startCamelContextIfNotStarted(GatewayService.java:143)
at com.xyz.abc.inf.console.service.GatewayService.postStart(GatewayService.java:102)
... 2 more
引起:org.hibernate.exception.GenericJDBCException:无法打开连接
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.extractPhysicalConnection(ConnectionProxyHandler.java:82)
at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy103.prepareStatement(Unknown Source)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:147)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:145)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1854)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1831)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1811)
at org.hibernate.loader.Loader.doQuery(Loader.java:899)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
at org.hibernate.loader.Loader.doList(Loader.java:2516)
at org.hibernate.loader.Loader.doList(Loader.java:2502)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2332)
at org.hibernate.loader.Loader.list(Loader.java:2327)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:490)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1247)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:264)
... 13 more
引起:java.sql.SQLException:客户端尝试签出连接已超时。
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:527)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:292)
数据库服务器:Oracle 11g
客户端配置:
[root @ eighamq1~] #uname -a Linux eighamq1.nrifintech.com 2.6.18-194.el5#1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU / Linux
[root @ eighamq1~] #cat / etc / redhat-release 红帽企业Linux服务器版本5.5(Tikanga)
[root @ eighamq1~] #java -version java版本" 1.7.0" Java(TM)SE运行时环境(版本1.7.0-b147) Java HotSpot(TM)64位服务器VM(版本21.0-b17,混合模式)
[root @ eighamq1~] #mvn -v Apache Maven 3.0.4(r1232337; 2012-01-17 14:14:56 + 0530) Maven home:/usr/local/maven-3.0.4 Java版本:1.7.0,供应商:Oracle Corporation Java home:/usr/java/jdk1.7.0/jre 默认语言环境:en_US,平台编码:UTF-8 操作系统名称:" linux",版本:" 2.6.18-194.el5",arch:" amd64",family:" unix"
JDBC.properties
jdbc.database.driverClass = oracle.jdbc.OracleDriver
jdbc.database.url = jdbc:oracle:thin:@172.16.29.92:1521:d11gr21
jdbc.database.initialLimit = 1
jdbc.database.maxLimit = 5
jdbc.database.minLimit = 1
jpa.hibernate.dialectClass = org.hibernate.dialect.Oracle10gDialect
jdbc.database.initialPoolSize = 10
jdbc.database.minPoolSize = 5
jdbc.database.maxPoolSize = 20
jdbc.database.maxStatements = 0
jdbc.database.acquireIncrement = 5
jdbc.database.acquireRetryAttempts = 5
jdbc.database.checkoutTimeout = 1000
使用的工件:
ojdbc16-11.2.0.1.0.jar
c3p0-0.9.1.1.jar
hibernate-entitymanager : 4.1.12.Final
hibernate-commons-annotations : 4.0.1.Final
hibernate-c3p0 : 4.1.12.Final
hibernate-commons-annotations : 4.0.1.Final
hibernate-jpa-2.0-api : 1.0.1.Final
答案 0 :(得分:0)
oracle瘦驱动程序在内部使用Java Security api连接到oracle。 Linux中的Java安全性使用/ dev / random作为Entropy Gathering设备,而linux中的这个设备有时返回值很慢。这可能是因为连接无法快速打开。
您可以在命令行中更改设置的设备:
-Djava.security.egd=file:///dev/urandom
使用此属性指示您可以使用/ dev / urandom获取随机值,并且此设备非常快,因为它使用伪随机算法。
当您使用Oracle Thin Driver连接数据库以提高连接数据库的性能时,最好使用此属性。