Difficulty: Medium
Correct Answer: x and y are always equal and increase by one each line; one thread monopolizes execution
Explanation:
Introduction / Context:
This test explores synchronization and liveness. Because run() is synchronized on the shared Runnable instance, only one thread can execute it at a time. The infinite loop means the first thread that enters never releases the lock, so the second thread is blocked indefinitely.
Given Data / Assumptions:
Concept / Approach:
Mutual exclusion on the same monitor guarantees that increments of x and y occur together with no interference. Since the loop never ends, the first thread to acquire the monitor will print endlessly. The second thread will remain blocked on the monitor and never print.
Step-by-Step Solution:
Verification / Alternative check:
If the loop had a break or sleep with a synchronized block of smaller scope, the lock could be released and T2 might run later, but as written T1 monopolizes it.
Why Other Options Are Wrong:
Common Pitfalls:
Expecting both threads to alternate inside a synchronized infinite loop; misunderstanding that a synchronized method holds the lock for its entire duration.
Final Answer:
x and y are always equal and increase by one each line; one thread monopolizes execution
Discussion & Comments