To make it easier to discuss, let assume the following changes:
What the explanation was saying is "the synchronized method when run will check the lock against the instance of the object itself". In this case you have instance
testAand
testB.
Usually synchronized method is perfectly fine because you put it on to prevent concurrent access to data that
belong to that object instance.
In your case you are manipulating
static x and
y, which belong to the Test.class itself .. not instance of
Test. So your synchronized method is guarding the wrong door. That is why it does not make sense.
If you want to guard concurrent access to static variables, then you need to move the synchronized inside and use Test.class itself or another static variable object as the key.
[ April 18, 2008: Message edited by: Wirianto Djunaidi ]