About Question enthuware.ocpjp.v11.2.1754 :
Posted: Tue Jan 16, 2024 11:53 am
Option B: When a synchronized method ends with a checked exception, the intrinsic lock held by the thread is released automatically.
Option C: A thread will retain the intrinsic lock if the return from a synchronized method is caused due to an uncaught unchecked exception. (Explanation of this: The intrinsic lock is released when the method ends. Irrespective of how it ends.)
I understood option B but I didn't fully understand option C. Is the only difference between them their exception type? If I understood correctly, synchronized method throws checked exception, the intrinsic lock is released but synchronized method throws unchecked exception, the intrinsic lock is NOT released.
Option C: A thread will retain the intrinsic lock if the return from a synchronized method is caused due to an uncaught unchecked exception. (Explanation of this: The intrinsic lock is released when the method ends. Irrespective of how it ends.)
I understood option B but I didn't fully understand option C. Is the only difference between them their exception type? If I understood correctly, synchronized method throws checked exception, the intrinsic lock is released but synchronized method throws unchecked exception, the intrinsic lock is NOT released.