• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Deadlock

 
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How this code can be deadlock?



Method a() can run easily
it calls method b()....

How can it be deadlock?

 
Master Rancher
Posts: 4271
57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty sure it can't create a deadlock. Certainly not by itself. Did someone tell you there was a problem? You probably need to ask them what they meant. And consider the possibility that they are simply wrong.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yea this can not result into a deadlock else it will defeat the whole reentrant locking mechanism.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you show me how to use JVM thread dump to find deadlock?

I mean a please instance very simple program that has deadlock , extract its thread dump and point how to use thread dump of that code to find deadlock

Thanks in advance.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Why not use the one from Sun's tutorial: Deadlock Example?

Compile and and run the program.
After the following two messages appear:
"Alphonse: Gaston has bowed to me!"
"Gaston: Alphonse has bowed to me!",
press the following key sequence in the cmd/shell:
- CTRL + break (Win)
- CTRL + '\' (Unix)

You'll receive a thread dump.
Following is just a snip with a deadlock msg:
...
Found one Java-level deadlock:
=============================
"Thread-1":
waiting to lock monitor 0x01664624 (object 0x23701150, a Deadlock$Friend),
which is held by "Thread-0"
"Thread-0":
waiting to lock monitor 0x01665e84 (object 0x23701160, a Deadlock$Friend),
which is held by "Thread-1"

Java stack information for the threads listed above:
===================================================
"Thread-1":
at Deadlock$Friend.bowBack(Deadlock.java:16)
- waiting to lock <0x23701150> (a Deadlock$Friend)
at Deadlock$Friend.bow(Deadlock.java:13)
- locked <0x23701160> (a Deadlock$Friend)
at Deadlock$2.run(Deadlock.java:28)
at java.lang.Thread.run(Unknown Source)
"Thread-0":
at Deadlock$Friend.bowBack(Deadlock.java:16)
- waiting to lock <0x23701160> (a Deadlock$Friend)
at Deadlock$Friend.bow(Deadlock.java:13)
- locked <0x23701150> (a Deadlock$Friend)
at Deadlock$1.run(Deadlock.java:25)
at java.lang.Thread.run(Unknown Source)

Found 1 deadlock.
...

Hope this helps.


Regards,
Rok
 
Your mind is under my control .... your will is now mine .... read this tiny ad
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic