tag:blogger.com,1999:blog-8712770457197348465.post3323087244902128468..comments2024-03-19T01:04:48.783-07:00Comments on Javarevisited: How to check if a thread holds lock on a particular object in Java? Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-8712770457197348465.post-10045050455299559172015-05-27T00:41:49.700-07:002015-05-27T00:41:49.700-07:00@Gaurav, I think there is no way you can find from...@Gaurav, I think there is no way you can find from Thrad class what type of object's lock it is holding. Also there is no method to find even which locks, how many locks theread is holding currently, let me know if there exists something like that even in Java 8.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-39792335304004527052015-04-14T10:58:45.451-07:002015-04-14T10:58:45.451-07:00Is there a way to know the object whose lock a thr...Is there a way to know the object whose lock a thread is holding?Anonymoushttps://www.blogger.com/profile/03524205286470198402noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-24853478033430330572014-12-15T22:26:52.977-08:002014-12-15T22:26:52.977-08:00Does anyone remember a situation where you want to...Does anyone remember a situation where you want to check if a thread holds a particular lock or not? I have never used this method, neither that I have needed it. I have only been asked this question one time on a telephonic interview with HSBC technology India. I see the point of surprise but this question is not practical. Kedarnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-67629163688424578442011-02-02T19:07:35.115-08:002011-02-02T19:07:35.115-08:00Hi Gautam,
Yes Thread.holdslock() is the best way...Hi Gautam,<br /><br />Yes Thread.holdslock() is the best way to figure out whether thread holds a lock on a particular object or not, let us know if you have some other ways to do it.<br /><br />Thanks<br />JavinJavin @ Tibco RV Tutorialhttp://javarevisited.blogspot.comnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-27141338844980967002011-01-31T03:58:41.931-08:002011-01-31T03:58:41.931-08:00Hi CARFIELD, yes jconsole can be used to monitor ...Hi CARFIELD, yes jconsole can be used to monitor threads but that's not the programmatic way of doing it . you may be able to know which thread holds a lock by using ThreadMXBean in java 5 in a programe.<br /><br />I have also discussed way to find out <a href="http://javarevisited.blogspot.com/search/label/thread" rel="nofollow">deadlock in java </a> which is related to this. Please have a Javin @ Tibco RV Tutorialhttp://javarevisited.blogspot.comnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-25890740634858125272011-01-30T19:44:06.630-08:002011-01-30T19:44:06.630-08:00How about using jconsole to check?How about using jconsole to check?CARFIELDhttps://www.blogger.com/profile/13094952618057460795noreply@blogger.com