DB2 驱动程序连接挂在 Glassfish 连接池中
我们在使用 Glassfish 连接池的 DB2 时遇到间歇性问题。发生的情况是这样的:
在数据库(ZOS 上的 DB2)承受压力的情况下,我们的应用程序(这是一个通过 Glassfish 连接池使用到 DB2 的连接的多线程应用程序)停止执行任何操作。
观察到以下情况:
1) 使用 JConsole 查看服务器,我们可以看到一个线程在 DB2 驱动程序的 getConnection() 方法中无限期地等待。我们还可以看到它已经获得了驱动程序内 Vector 的锁定。其他几个线程也在调用驱动程序中的 getConnection() 方法,并挂起等待 Vector 上的锁被释放。
2) 查看数据库本身,我们可以看到来自 Glassfish 服务器的连接已打开并等待使用。 Glassfish 上的连接池与实际向 DB2 打开的连接之间似乎存在某种不匹配。
以前有人遇到过这个问题吗?或者类似的东西?如果您需要我未提供的更多信息,请告诉我!
We have an intermittent issue around the DB2 used from a Glassfish connection pool. What happens is this:
Under situations where the database (DB2 on ZOS) is under stress, our application (which is a multi-threaded application using connections to DB2 via a Glassfish connection pool) stops doing anything.
The following are observed:
1) Looking at the server using JConsole, we can see a thread waiting indefinitely in the DB2 driver's getConnection() method. We can also see that it has gained a lock on a Vector within the driver. Several other threads are also calling the getConnection() method in the driver, and are hanging waiting for the lock on the Vector to be released.
2) Looking at the database itself, we can see that there are connections from the Glassfish server open and waiting to be used. It seems that there is some sort of mismatch between the connection pool on Glassfish and the connections actually open to DB2.
Has anyone come across this issue before? Or something similar? If you need any more information that I haven't provided, then please let me know!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许相关:
https://bugs.java.com/bugdatabase/view_bug?bug_id=4263113
你是jdk1.5吗?
来自博客:
在 Java 1.5 及更早版本中,java.sql.DriverManager 上的所有方法都是同步的。您对 DriverManager.getConnection(...) 的初始调用会触发 HA-JDBC 的启动。当 HA-JDBC 初始化时,它最终将为集群中的每个数据库 url 调用 DriverManager.getDriver(...)。对 DriverManager.getDriver(...) 的调用发生在与应用程序线程不同的线程中,因此出现死锁。
对于此问题,至少有 2 个已知的解决方法:
升级到 Java 1.6。在一直坚持 java.sql.DriverManager 的全面同步不是一个缺陷之后,Sun 在 Java 1.6 中默默地修复了这个问题。
不要使用 DriverManager.getConnection(...) 来获取连接,而是使用 DriverManager.getDriver(...).connect(...) 。这将避免死锁,因为 DriverManager.getDriver(...) 不会触发 HA-JDBC 启动,并且 Driver.connect(...) 不会同步。
Related perhaps:
https://bugs.java.com/bugdatabase/view_bug?bug_id=4263113
are you on jdk1.5 ?
From a blog:
In Java 1.5 and earlier, all of the methods on java.sql.DriverManager are synchronized. Your initial call to DriverManager.getConnection(...) triggers the startup of HA-JDBC. As HA-JDBC initializes, it will eventually call DriverManager.getDriver(...) for each database url in your cluster. The calls to DriverManager.getDriver(...) occur in a different thread from your application thread, hence the deadlock.
There are at least 2 known workarounds for this problem:
Upgrade to Java 1.6. After forever insisting that the blanket synchronization of java.sql.DriverManager was not a defect, Sun silently fixed this in Java 1.6.
Rather than use DriverManager.getConnection(...) to obtain connections, use DriverManager.getDriver(...).connect(...) instead. This will circumvent the deadlock since DriverManager.getDriver(...) will not trigger HA-JDBC startup and Driver.connect(...) is not synchronized.