java – JDBC驱动程序注册死锁?
作者:互联网
在一个线程中,正在创建一个JackRabbit:
"docs-on-startup" #32 prio=5 os_prio=0 tid=0x00007f730d73e800 nid=0x601d in Object.wait() [0x00007f725bffc000]
java.lang.Thread.State: RUNNABLE
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at java.sql.DriverManager$2.run(DriverManager.java:603)
at java.sql.DriverManager$2.run(DriverManager.java:583)
at java.security.AccessController.doPrivileged(Native Method)
at java.sql.DriverManager.loadInitialDrivers(DriverManager.java:583)
at java.sql.DriverManager.<clinit>(DriverManager.java:101)
at org.apache.derby.jdbc.EmbeddedDriver.boot(Unknown Source)
at org.apache.derby.jdbc.EmbeddedDriver.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.jackrabbit.core.util.db.ConnectionFactory.getDriverClass(ConnectionFactory.java:261)
at org.apache.jackrabbit.core.util.db.ConnectionFactory.createDataSource(ConnectionFactory.java:234)
at org.apache.jackrabbit.core.util.db.ConnectionFactory.getDataSource(ConnectionFactory.java:170)
- locked <0x000000066c71ea70> (a java.lang.Object)
at org.apache.jackrabbit.core.persistence.pool.BundleDbPersistenceManager.getDataSource(BundleDbPersistenceManager.java:569)
at org.apache.jackrabbit.core.persistence.pool.BundleDbPersistenceManager.init(BundleDbPersistenceManager.java:537)
at org.apache.jackrabbit.core.persistence.pool.DerbyPersistenceManager.init(DerbyPersistenceManager.java:250)
at org.apache.jackrabbit.core.RepositoryImpl.createPersistenceManager(RepositoryImpl.java:1375)
at org.apache.jackrabbit.core.RepositoryImpl.createVersionManager(RepositoryImpl.java:512)
at org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:313)
at org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:615)
在另一个线程中,使用Class.forName(“org.postgresql.Driver”)初始化Postgres的驱动程序:
"schema-task-1" #37 prio=5 os_prio=0 tid=0x00007f725402b000 nid=0x6021 in Object.wait() [0x00007f725baf9000]
java.lang.Thread.State: RUNNABLE
at org.postgresql.Driver.register(Driver.java:730)
at org.postgresql.Driver.<clinit>(Driver.java:70)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
没有一个线程正在完成它的任务,不确定理解为什么.初始化JDBC驱动程序的方法有什么问题吗?
解决方法:
看看堆栈跟踪,问题似乎是JackRabbit
>正在加载Derby嵌入式驱动程序类,
>触发注册,
>触发java.sql.DriverManager的类加载,
>触发java.sql.DriverManager通过JDBC 4服务加载器机制加载驱动程序,
>触发Derby嵌入式驱动程序实例的构造,该实例必须等到步骤1的类加载完成.
由于类加载不是可重入的(据我所知),这会导致一切都停止.加载DriverManager等待Derby驱动程序,它等待DriverManager.当您还尝试加载PostgreSQL驱动程序时,它还必须等待DriverManager.
这是导致这种情况的理论,我可能是错的(因为如果这个理论是正确的,我会认为它是一个更常见的问题).我将做一些测试,看看我是否可以重现这一点,并在必要时向Oracle报告.
解决这个问题的真正方法是,不使用Class.forName加载驱动程序,而是依赖于JDBC驱动程序自动加载.然而,这似乎表明DriverManager如何工作的缺陷.
解决方法可能是确保java.sql.DriverManager已经被分类(例如,在调用RepositoryImpl.create之前,通过在某些初始化代码中调用其中一个方法(例如DriverManager.getLoginTimeout()).
另一种解决方法是修改JDBC驱动程序jar并删除/META-INF/services/java.sql.Driver文件;这将禁用驱动程序自动加载.
标签:java,postgresql,jdbc,jackrabbit 来源: https://codeday.me/bug/20190611/1219864.html