Sample61 is run - what will be the output?
public class Sample61
{
public static void main(String[] args)
{
final Object lock = new Object();
System.out.print(Thread.holdsLock(lock) + " ");
synchronized (lock)
{
System.out.print(Thread.holdsLock(lock));
}
}
}
Answer: A
holdsLock reports whether the current thread owns the monitor of the given object at that moment. Outside the synchronized block it does not, and inside it does. The method exists for assertions and diagnostics rather than for control flow.
Please log in or register to report this question.