• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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?

 
Rancher
Posts: 4062
56
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic