- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我使用 Oracle 数据库,我的 java 应用程序使用 Hibernate 3.3.2 与之交互。
我总是使用这样的代码连接到数据库
public void method() {
Session session = HibernateSessionFactory.getSessionFactory().openSession();
String sqlSelect = "SELECT sql ...";
Transaction tran = session.beginTransaction();
SQLQuery sqlSelectQuery = session.createSQLQuery(sqlSelect).;
sqlSelectQuery.setString("PARAM", param);
boolean ok = true;
try {
List list = sqlSelectQuery.list();
if (list.size() > 0) {
String updateSql = "UPDATE ....";
SQLQuery updateQuery = session.createSQLQuery(updateSql);
updateQuery.setString("PARAM", param);
updateQuery.executeUpdate();
}
} catch (Exception ex) {
ok = false;
tran.rollback();
ex.printStackTrace()
}
try {
if (ok) {
tran.commit();
}
session.close();
} catch (Exception ex) {
ex.printStackTrace()
}
}
它工作完美,永远不会出错。
但是当我更改为:(仅添加 try、catch,最后完全关闭 hibernate session )
public void method() {
Session session = null
try{
session = HibernateSessionFactory.getSessionFactory().openSession();
String sqlSelect = "SELECT sql ...";
Transaction tran = session.beginTransaction();
SQLQuery sqlSelectQuery = session.createSQLQuery(sqlSelect).;
sqlSelectQuery.setString("PARAM", param);
boolean ok = true;
try {
List list = sqlSelectQuery.list();
if (list.size() > 0) {
String updateSql = "UPDATE ....";
SQLQuery updateQuery = session.createSQLQuery(updateSql);
updateQuery.setString("PARAM", param);
updateQuery.executeUpdate();
}
} catch (Exception ex) {
ok = false;
tran.rollback();
ex.printStackTrace()
}
try {
if (ok) {
tran.commit();
}
session.close();
} catch (Exception ex) {
ex.printStackTrace()
}
}catch (HibernateException hibernateException) {
hibernateException.printStackTrace();
} finally {
if ((session != null) && (session.isOpen())) {
session.close();
}
}
}
然后我得到了很多明显的死锁。
[Timer-2] 24/06/2014 21:33:11 WARN ThreadPoolAsynchronousRunner: Task com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@1e093f32 (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt().
[Timer-2] 24/06/2014 21:33:11 WARN ThreadPoolAsynchronousRunner: Task com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@7113fb05 (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt().
[Timer-2] 24/06/2014 21:33:11 WARN ThreadPoolAsynchronousRunner: Task com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@56c53f42 (in deadlocked PoolThread) failed to complete in maximum time 60000ms. Trying interrupt().
[Timer-2] 24/06/2014 21:33:11 WARN ThreadPoolAsynchronousRunner: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@47ecfc46 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!
[Timer-2] 24/06/2014 21:33:11 WARN ThreadPoolAsynchronousRunner: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@47ecfc46 -- APPARENT DEADLOCK!!! Complete Status:
Managed Threads: 3
Active Threads: 3
Active Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@72937d83 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@31155e39 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@71dd095b (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
Pending Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@66916fc3
com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask@56409fd0
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@2cbc3ced
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@7a44028c
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@703740a
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@73b7401e
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@3d2acec
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@7c56bbe9
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@224afdc5
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@695aa219
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@3d484d58
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@55cdebd6
Pool thread stack traces:
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.read(SocketInputStream.java:129)
oracle.net.ns.Packet.receive(Unknown Source)
oracle.net.ns.DataPacket.receive(Unknown Source)
oracle.net.ns.NetInputStream.getNextPacket(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:971)
oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:941)
oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:432)
oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181)
oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:420)
oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:896)
oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:452)
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:986)
oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2888)
oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2929)
oracle.jdbc.OracleDatabaseMetaData.getTables(OracleDatabaseMetaData.java:2311)
com.mchange.v2.c3p0.impl.DefaultConnectionTester.activeCheckConnectionNoQuery(DefaultConnectionTester.java:185)
com.mchange.v2.c3p0.impl.DefaultConnectionTester.activeCheckConnection(DefaultConnectionTester.java:62)
com.mchange.v2.c3p0.AbstractConnectionTester.activeCheckConnection(AbstractConnectionTester.java:67)
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.testPooledConnection(C3P0PooledConnectionPool.java:368)
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.refurbishIdleResource(C3P0PooledConnectionPool.java:310)
com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.run(BasicResourcePool.java:1999)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.read(SocketInputStream.java:129)
oracle.net.ns.Packet.receive(Unknown Source)
oracle.net.ns.DataPacket.receive(Unknown Source)
oracle.net.ns.NetInputStream.getNextPacket(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:971)
oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:941)
oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:432)
oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181)
oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:420)
oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:896)
oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:452)
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:986)
oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2888)
oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2929)
oracle.jdbc.OracleDatabaseMetaData.getTables(OracleDatabaseMetaData.java:2311)
com.mchange.v2.c3p0.impl.DefaultConnectionTester.activeCheckConnectionNoQuery(DefaultConnectionTester.java:185)
com.mchange.v2.c3p0.impl.DefaultConnectionTester.activeCheckConnection(DefaultConnectionTester.java:62)
com.mchange.v2.c3p0.AbstractConnectionTester.activeCheckConnection(AbstractConnectionTester.java:67)
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.testPooledConnection(C3P0PooledConnectionPool.java:368)
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.refurbishIdleResource(C3P0PooledConnectionPool.java:310)
com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.run(BasicResourcePool.java:1999)
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(SocketInputStream.java:129)
oracle.net.ns.Packet.receive(Unknown Source)
oracle.net.ns.DataPacket.receive(Unknown Source)
oracle.net.ns.NetInputStream.getNextPacket(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.net.ns.NetInputStream.read(Unknown Source)
oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:971)
oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:941)
oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:432)
oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:181)
oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:420)
oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:896)
oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:452)
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:986)
oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2888)
oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2929)
oracle.jdbc.OracleDatabaseMetaData.getTables(OracleDatabaseMetaData.java:2311)
com.mchange.v2.c3p0.impl.DefaultConnectionTester.activeCheckConnectionNoQuery(DefaultConnectionTester.java:185)
com.mchange.v2.c3p0.impl.DefaultConnectionTester.activeCheckConnection(DefaultConnectionTester.java:62)
com.mchange.v2.c3p0.AbstractConnectionTester.activeCheckConnection(AbstractConnectionTester.java:67)
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.testPooledConnection(C3P0PooledConnectionPool.java:368)
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.refurbishIdleResource(C3P0PooledConnectionPool.java:310)
com.mchange.v2.resourcepool.BasicResourcePool$AsyncTestIdleResourceTask.run(BasicResourcePool.java:1999)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
这是我的 hibernate 配置 c3p0
<property name="connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">50</property>
<property name="hibernate.c3p0.timeout">5</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.idle_test_period">60</property>
我可以在我的代码中找到错误,但它会导致“明显的死锁异常”我能做什么?
最佳答案
失败的是检查空闲连接是否仍然有效的测试线程。显然,默认查询 getTables()
只是获取架构中所有表的列表,正在超时。这是否是数据库崩溃很难说,但是你没有通过 5 秒的超时来帮助事情,这导致你每 5 秒关闭并重新打开所有 5 个连接。将其设置为合理的值,例如 1800。您也可以尝试设置不同的连接测试,或者完全关闭连接测试。
此配置关闭空闲测试并将超时设置得更高:
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">50</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">0</property>
关于java - Hibernate 更改某行代码得到明显的死锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24399211/
猫f1.txt阿曼维沙尔阿杰贾伊维杰拉胡尔曼尼什肖比特批评塔夫林现在输出应该符合上面给定的条件 最佳答案 您可以在文件读取循环中设置一个计数器并打印它, 计数=0 读取行时做 让我们数一数++ if
我正在尝试查找文件 1 和文件 2 中的共同行。如果公共(public)行存在,我想写入文件 2 中的行,否则打印文件 1 中的非公共(public)行。fin1 和 fin2 是这里的文件句柄。它读
我有这个 SQL 脚本: CREATE TABLE `table_1` ( `IDTable_1` int(11) NOT NULL, PRIMARY KEY (`IDTable_1`) );
我有 512 行要插入到数据库中。我想知道提交多个插入内容是否比提交一个大插入内容有任何优势。例如 1x 512 行插入 -- INSERT INTO mydb.mytable (id, phonen
如何从用户中选择user_id,SUB(row, row - 1),其中user_id=@userid我的表用户,id 为 1、3、4、10、11、23...(不是++) --id---------u
我曾尝试四处寻找解决此问题的最佳方法,但我找不到此类问题的任何先前示例。 我正在构建一个基于超本地化的互联网购物中心,该区域分为大约 3000 个区域。每个区域包含大约 300 个项目。它们是相似的项
preg_match('|phpVersion = (.*)\n|',$wampConfFileContents,$result); $phpVersion = str_replace('"','',
我正在尝试创建一个正则表达式,使用“搜索并替换全部”删除 200 个 txt 文件的第一行和最后 10 行 我尝试 (\s*^(\h*\S.*)){10} 删除包含的前 10 行空白,但效果不佳。 最
下面的代码从数据库中获取我需要的信息,但没有打印出所有信息。首先,我知道它从表中获取了所有正确的信息,因为我已经在 sql Developer 中尝试过查询。 public static void m
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我试图在两个表中插入记录,但出现异常。您能帮我解决这个问题吗? 首先我尝试了下面的代码。 await _testRepository.InsertAsync(test); await _xyzRepo
这个基本的 bootstrap CSS 显示 1 行 4 列: Text Text Text
如果我想从表中检索前 10 行,我将使用以下代码: SELECT * FROM Persons LIMIT 10 我想知道的是如何检索前 10 个结果之后的 10 个结果。 如果我在下面执行这段代码,
今天我开始使用 JexcelApi 并遇到了这个:当您尝试从特定位置获取元素时,不是像您通常期望的那样使用sheet.getCell(row,col),而是使用sheet.getCell(col,ro
我正在尝试在我的网站上开发一个用户个人资料系统,其中包含用户之前发布的 3 个帖子。我可以让它选择前 3 条记录,但它只会显示其中一条。我是不是因为凌晨 2 点就想编码而变得愚蠢? query($q)
我在互联网上寻找答案,但找不到任何答案。 (我可能问错了?)我有一个看起来像这样的表: 我一直在使用查询: SELECT title, date, SUM(money) FROM payments W
我有以下查询,我想从数据库中获取 100 个项目,但 host_id 多次出现在 urls 表中,我想每个 host_id 从该表中最多获取 10 个唯一行。 select * from urls j
我的数据库表中有超过 500 行具有特定日期。 查询特定日期的行。 select * from msgtable where cdate='18/07/2012' 这将返回 500 行。 如何逐行查询
我想使用 sed 从某一行开始打印 n 行、跳过 n 行、打印 n 行等,直到文本文件结束。例如在第 4 行声明,打印 5-9,跳过 10-14,打印 15-19 等 来自文件 1 2 3 4 5 6
我目前正在执行验证过程来检查用户的旧密码,但问题是我无法理解为什么我的查询返回零行,而预期它有 1 行。另一件事是,即使我不将密码文本转换为 md5,哈希密码仍然得到正确的答案,但我不知道为什么会发生
我是一名优秀的程序员,十分优秀!