aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes holdsLock() method in Thread class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "holdsLock() method in Thread class" Watch "holdsLock() method in Thread class" New topic
Author

holdsLock() method in Thread class

Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
I thought that above method will only return true if it is called from within a synchronized method/code block. But one of mock exam asserts otherwise....
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12779
    
    5
According to the JavaDocs for java.lang.Thread, holdsLock( Object ) is a static method in the Thread class - it returns false if the executing Thread does not hold a lock on the object specified, true if it does. Locks that the current Thread may have on the object where the method is executed are irrelevant.
Bill
[ August 13, 2003: Message edited by: William Brogden ]
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Hi Bill:
In that case the code below should printout "false" because amethod() is not synchronized... Right?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
In that case the code below should printout "false" because amethod() is not synchronized... Right?
Have you tested the code to see?


"I'm not back." - Bill Harding, Twister
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
I just did. I figured the problem. It was not related to lock issue. It was just that assert was not enabled at run time while I presumed it was....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: holdsLock() method in Thread class