Is it possible to check whether a thread holds a monitor lock on some given object?

By | September 22, 2019

In this blog post we will talk and learn about one of very important multi Threading Java interview question and question is that Is it possible to check whether a thread holds a monitor lock on some given object?

We have method in class java.lang.Thread which provides the static method Thread.holdsLock(Object) that returns true if and only if the current thread holds the lock on the given object as argument to the method invocation.

Let’s try to understand using an Example..

Output

That’s all about  Is it possible to check whether a thread holds a monitor lock on some given object?
If you have any feedback or suggestion please feel free to drop in blow comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *