In Java, Thread class has a static method holdsLock(Object
objToCheck) to check whether thread has a lock on objToLock
object.
This method will return true if current thread holds the lock on the
objToLock object that was passed as an argument to this method
https://www.geeksforgeeks.org/how-to-check-if-a-thread-holds-lock-on-a-particular-object-in-java/