• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can one prove that lock has been acquired on an object  RSS feed

 
shesh anand
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can one prove that lock has been acquired on an object and funny enough not on thread....stupid is not it!!!
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is there to prove in it?
 
Meghna Bhardwaj
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there is a static boolean holdsLock(Object obj) method, which will give you a true false if the object is locked.

I just took it as a given, and didnt fight it
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that Thread.holdsLock() is broken in older Java versions, including 1.4. I had used it in various assertions, and kept getting spurious assertion failures.

Thread.holdsLock() works correctly in Java 6.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!