In program 1, two threads are syncronized with static Object o = new Object();
, which is class variable. Only one of two thread can enter the synchronized block.
But each of the threads in program 2 is synchronized with itself. One does not wait for the other releasing the lock. They are executed independantly.
If the variable o
is declared as instance member of class T ( without static
), the result is same as program 2.