论坛首页 入门技术论坛

Hibernate如何稳定连接多数据库?

浏览 7867 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-11-13  

做了一个用Hibernate切换连接多个sqlserver数据库的程序,开始用ms的sqlserver驱动,用一段时间以后就会出现connection reset exception,后面改为jtds驱动+c3p0连接池,但还是不稳定,会报异常。不知道有什么好的方法能解决不稳定问题?

   发表时间:2007-11-19  
异常信息如下:
java.lang.InterruptedException: sleep interrupted
        at java.lang.Thread.sleep(Native Method)
        at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicRe
sourcePool.java:1805)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(Thre
adPoolAsynchronousRunner.java:547)
- com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@188e804 --
APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
- com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@188e804 --
APPARENT DEADLOCK!!! Complete Status:
        Managed Threads: 3
        Active Threads: 3
        Active Tasks:
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@bb0a41
(com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@19e61f
d (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1334ec
d (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
        Pending Tasks:
                com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResou
rceTask@17a941e
                com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResou
rceTask@9278cc
Pool thread stack traces:
        Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5
,main]
                java.net.SocketInputStream.socketRead0(Native Method)
                java.net.SocketInputStream.read(Unknown Source)
                java.io.DataInputStream.readFully(Unknown Source)
                java.io.DataInputStream.readFully(Unknown Source)
                net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.j
ava:841)
                net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket
.java:722)
                net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStrea
m.java:466)
                net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.jav
a:103)
                net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2202)
                net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:602)
                net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2
.java:344)
                net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3
.java:50)
                net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:182)
                com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(Driver
ManagerDataSource.java:134)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledCon
nection(WrapperConnectionPoolDataSource.java:182)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledCon
nection(WrapperConnectionPoolDataSource.java:171)
                com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnect
ionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
                com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicRes
ourcePool.java:1014)
                com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicRe
sourcePool.java:32)
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(Ba
sicResourcePool.java:1810)
                com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run
(ThreadPoolAsynchronousRunner.java:547)
        Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5
,main]
                java.net.SocketInputStream.socketRead0(Native Method)
                java.net.SocketInputStream.read(Unknown Source)
                java.io.DataInputStream.readFully(Unknown Source)
                java.io.DataInputStream.readFully(Unknown Source)
                net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.j
ava:841)
                net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket
.java:722)
                net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStrea
m.java:466)
                net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.jav
a:103)
                net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2202)
                net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:602)
                net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2
.java:344)
                net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3
.java:50)
                net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:182)
                com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(Driver
ManagerDataSource.java:134)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledCon
nection(WrapperConnectionPoolDataSource.java:182)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledCon
nection(WrapperConnectionPoolDataSource.java:171)
                com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnect
ionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
                com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicRes
ourcePool.java:1014)
                com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicRe
sourcePool.java:32)
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(Ba
sicResourcePool.java:1810)
                com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run
(ThreadPoolAsynchronousRunner.java:547)
        Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5
,main]
                java.net.SocketInputStream.socketRead0(Native Method)
                java.net.SocketInputStream.read(Unknown Source)
                java.io.DataInputStream.readFully(Unknown Source)
                java.io.DataInputStream.readFully(Unknown Source)
                net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.j
ava:841)
                net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket
.java:722)
                net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStrea
m.java:466)
                net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.jav
a:103)
                net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2202)
                net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:602)
                net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2
.java:344)
                net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3
.java:50)
                net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:182)
                com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(Driver
ManagerDataSource.java:134)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledCon
nection(WrapperConnectionPoolDataSource.java:182)
                com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledCon
nection(WrapperConnectionPoolDataSource.java:171)
                com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnect
ionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
                com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicRes
ourcePool.java:1014)
                com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicRe
sourcePool.java:32)
                com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(Ba
sicResourcePool.java:1810)
                com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run
(ThreadPoolAsynchronousRunner.java:547)


- Task com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@e7fe3c (in dead
locked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(
).
- com.mchange.v2.resourcepool.BasicResourcePool@1e8b63d -- Thread unexpectedly i
nterrupted while performing an acquisition attempt.
java.lang.InterruptedException: sleep interrupted
        at java.lang.Thread.sleep(Native Method)
        at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicRe
sourcePool.java:1805)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(Thre
adPoolAsynchronousRunner.java:547)
- Task com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@e43775 (in dead
locked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(
).
- Task com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@f4e8ef (in dead
locked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt(
).
0 请登录后投票
   发表时间:2007-11-29  
有时候简单的东西性能反而是最好的。当去掉Hibernate改用JDBC连接数据库以后什么问题都解决了,切换数据库速度快,连接稳定。(JDBC驱动用的:jtds)
这让我有点怀疑Hibernate的性能,在对JDBC做轻量级封装以后,性能也不至于下降的这么厉害吧,让我痛苦了快2个月。。。
0 请登录后投票
   发表时间:2007-11-29  
hibernate不止你一个人再用啊朋友
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics