Connection lock = getConnection();
lock.setAutoCommit(false);
lock.createStatement().execute("select * from zhaojianyong for update");
final Connection connection = getConnection();
connection.setAutoCommit(false);
new Thread(){
@Override
public void run() {
try {
Thread.sleep(10 * 1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
try {
System.out.println("begin commit");
connection.commit();
System.out.println("end commit");
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}.start();
connection.createStatement().execute("update zhaojianyong set id= 8 where id != 0");
以上的程序会怎么运行呢???
Connection的并发问题,我感觉JDBC规范里说得很模糊。
不知道如果一个连接正在更新,在另一个线程中close commit rollback会怎么样。
有没有牛人能解答。。。
本文探讨了JDBC中Connection的并发使用问题,特别是在多线程环境下如何处理更新操作及其实现细节。通过一个示例程序,分析了当一个连接正在进行更新时,其他线程尝试关闭、提交或回滚该连接可能产生的影响。
1万+

被折叠的 条评论
为什么被折叠?



