top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to find if a thread holds lock on particular object in Java?

+3 votes
How to find if a thread holds lock on particular object in Java?
posted Jun 1, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

2 ways to find if thread holds lock on object in Java

1)I thought about IllegalMonitorStateException which wait() and notify() methods throw when they get called from non-synchronized context so I said I would call newspaper.wait() and if this call throws exception it means thread in java is not holding lock, otherwise thread holds lock.

2)Another Way is that thread is a static method called holdsLock(Object obj) which returns true or false based on whether threads holds lock on object passed.

answer Jun 17, 2015 by Karthick.c
Similar Questions
+2 votes

Given string representation of an object and a list of classes. How would you determine what class that object belongs to?

+5 votes

Can a lock be acquired on a class if yes then how?

+2 votes

Java does not have sizeof operator now my question is How to find out how much memory is used by an object in Java?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.