This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I'm confused with the deadlock exampl in Java Tutorial.

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In my machine, the result is:
Alphonse: Gaston has bowed to me!
Gaston: Alphonse has bowed back to me!
Gaston: Alphonse has bowed to me!
Alphonse: Gaston has bowed back to me!

Why doesn't the code hang there? If the result is OK,what does the deadlock mean?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Run this enough times, and it should indeed hang. Try putting a loop in main() to run this 500 times. It's a timing issue; whether or not it hangs depends on how quickly the second thread can be started.

I just compiled and ran your program and it hung the first time!
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I add the loop as you suggested. Now it hangs there.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic