为什么Java无法从死锁中恢复? [英] Why java does not recover from deadlock?

查看:86
本文介绍了为什么Java无法从死锁中恢复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读《 Java并发实践》一书,这是有关死锁的内容.

I am reading the book Java Concurrency in Practice, and here is what it says about deadlock.

JVM无法从死锁中恢复,并且是摆脱死锁的唯一方法 锁定是重新启动服务器.它还提到JVM使用图 搜索线程在其中充当图节点和两个线程之间的边A 并且B被定义为线程A正在等待资源锁定 由线程B保持.此图是有向的,并且如果存在任何循环, 此图,然后出现死锁

JVM does not recover from deadlock, and only way to get rid of dead lock is to restart the server. It also mentions that JVM uses graph search where Thread acts as graph node and edge between two threads A and B is defined as Thread A is waiting for lock on resource already held by thread B. This graph is directed and if there is any cycle in this graph, then there is deadlock

现在我的问题是,如果JVM知道存在死锁,那么为什么它不杀死一个线程而让其他线程继续呢?这背后是否有任何特定原因,或者我的问题本身是基于错误的结论?

Now my question is that if JVM knows that there is deadlock, then why does not it kill one thread and let other proceed? is there any specific reason behind this or my question itself is based on wrong conclusion?

请让我知道您对此的看法.预先谢谢!!!

Please let me know your views about this. Thanks in advance!!!

推荐答案

现在我的问题是,如果JVM知道存在死锁,那么为什么它不杀死一个线程而让其他线程继续呢?这背后是否有任何特定原因,或者我的问题本身是基于错误的结论?

Now my question is that if JVM knows that there is deadlock, then why does not it kill one thread and let other proceed? is there any specific reason behind this or my question itself is based on wrong conclusion?

JVM如何决定要杀死哪个线程?如果JVM在强制解除锁定的情况下允许无效数据进入某种关键数据库,该怎么办?

How could the JVM make the decision about which thread to kill? What if the JVM, in releasing the lock by force, allowed invalid data to enter some sort of critical database?

JVM无法任意做出此类决定.它会报告死锁,但无法自动从死锁中恢复.

The JVM cannot make these sort of decisions arbitrarily. It reports on the deadlock but cannot automagically recover from it.

在用锁修改两个关键对象但两个线程以不同顺序锁定它们的任何情况下,您都可能会看到此问题.数据库事务能够从此类死锁中恢复,因为它们旨在回滚表和索引,但是Java同步锁不具有隐式内存回滚功能.通过杀死一个线程并释放其锁,JVM将允许传播部分内存更新.

You could see this problem in any situation where two critical objects are being modified with locks but two threads are locking them in a different order. Database transactions are able to recover from such deadlocks because they are designed to roll back tables and indices but Java synchronized locks don't have implicit memory rollback capabilities. By killing one thread and releasing its locks, the JVM would be allowing partial memory updates to be propagated.

这篇关于为什么Java无法从死锁中恢复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆