jjzjj

alphonse

全部标签

java - Sun教程中关于死锁的一个问题

下面是直接来自描述死锁的Sun教程的代码。但是,考虑到两种方法都是同步的,我不明白在这种情况下如何发生死锁。两个线程如何同时在同一个同步方法中?死锁描述了两个或多个线程永远阻塞,互相等待的情况。这是一个例子。Alphonse和Gaston是friend,而且非常讲究礼貌。一个严格的礼貌规则是,当你向friend鞠躬时,你必须一直鞠躬,直到你的friend有机会还礼。不幸的是,这条规则没有考虑到两个friend可能同时互相鞠躬的可能性。这个示例应用程序Deadlock模拟了这种可能性:publicclassDeadlock{staticclassFriend{privatefinalSt

java - 关于Java死锁情况的问题

我正在学习Java中的死锁,并且有来自Sun官方教程的示例代码:AlphonseandGastonarefriends,andgreatbelieversincourtesy.Astrictruleofcourtesyisthatwhenyoubowtoafriend,youmustremainboweduntilyourfriendhasachancetoreturnthebow.Unfortunately,thisruledoesnotaccountforthepossibilitythattwofriendsmightbowtoeachotheratthesametime.pub