Java Thread holdLock() methodThe holdLock() method of thread class returns true if the current thread holds the monitor lock on the specified object. SyntaxParameterobj: It defines the object on which to test lock ownership ReturnIt returns true if and only if the current thread holds the monitor lock on the specified object. Otherwise, it returns false. ExceptionNullPointerException: This exception throws if obj is null.ExampleTest it NowOutput: Currently executing thread is: Thread-0 Does thread holds lock? false Does thread holds lock? true Next TopicMultithreading Java |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India