gpt4 book ai didi

java - MySQL JDBC : Is there an option for automatic retry after InnoDB deadlock?

转载 作者:可可西里 更新时间:2023-11-01 06:30:40 25 4
gpt4 key购买 nike

我是Working around MySQL error “Deadlock found when trying to get lock; try restarting transaction”

我发现可以安全地重试交易

Deadlocks are not dangerous. Just try again.
http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html

在选择两个其他表的连接组合并在瓶颈表和一些小表上使用子语句条件后,有一个“ super 插入..选择”语句插入到瓶颈表中。

瓶颈是“waiting for lock”,毫无疑问是在等待写锁。 InnoDB 似乎是完美的选择。 (对于写入繁重的表)现在对这一个语句的犹豫都消失了。

但现在问题来了:每执行 100 次语句,大约有 1 到 2 次会因为死锁而失败。我相信死锁只发生在“ super 插入..选择”的实例之间。我将安装该语句的自动重试,但我想知道

问题:MySQL JDBC 是否可以选择在收到异常后打开语句的自动重试,还是我必须为此编写自己的代码?

com.mysql.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction

在这种情况下,我没有启动交易或停止交易命令。就是那个“ super 插入..选择”语句

最佳答案

您可以重复该语句,但在理想情况下,您应该回滚事务并重新开始。在那个世界里你的交易会很短暂 :)

关于java - MySQL JDBC : Is there an option for automatic retry after InnoDB deadlock?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6987918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com