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
|