• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Deadlock explaination please

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone explain to me this piece of code and how the deadlock occured? thanks

[ June 07, 2007: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex,

Welcome to JavaRanch!

#1: It is bad practice to do like:
try{
Thread.sleep(500);
}catch (Exception e){}
}
How will you come to know what happened of exception if thrown!

#2: Root of deadlock:
DeadLock t1 = new DeadLock(obj1, obj2);
DeadLock t2 = new DeadLock(obj2, obj1);

The order or resources, the thread will work with:
->t1 will first acquire the lock of resourceA(obj1) and then go to grab the lock for resourceB(obj2).
->t1 will first acquire the lock of resourceA(obj2) and then go to grab the lock for resourceB(obj1).

Meanwhile if both the threads are having lock on one-one object, then they
will wait for the other object that can't be released. Waiting for each
other.



Thanks,
[ June 07, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, in future, enclose your properly indented code within code tags ().
 
ice is for people that are not already cool. Chill with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!