There are two threads created by the main method. However, when one of the threads enters the
run()
method, it acquires the lock on obj and enters into an infinite loop.
Now, the second thread also enters run but has to wait to acquire the same lock since obj is a
static field. So, in effect, only the thread that gets the lock first, keeps on running. The second thread never gets a chance. Therefore,
- the printed values are sequential,
- x and y are always printed as equal and
- they get incremented by 1 on each line.