Abhi vijay wrote:Here the output is fixed, right? As we it is synchronized with a String reference s??
But If I replace synchronized(new String("s")), then Output becomes unpredictable, right?
Output is not fixed. It differs from one JVM to another. The
thread t1 might go to runnable, but unless the thread scheduler pulls out the thread t1 from runnable pool to be thread of execution, the output is not fixed. It might be possible that the thread t2 might gain the access to be in running state before t1. So, my opinion. No the output is not fixed.