Posts

Showing posts from June, 2015
Can two threads call two different synchronized instance methods of an Object? No, If an object has synchronized instance methods then the Object itself is used a lock object for controlling the synchronization. Therefore all other instance methods need to wait until previous method call is completed. I have 4 methods (m1, m2, m3 and m4) in a class. m1, m2 and m3 are synchronized method. Also i have 4 threads t1, t2, t3 and t4 respectively. If t1 access the m1 method (synchronized method), could t2 thread access m2 method (synchronized method) simultaneously? If the methods are synchronized on the same monitor, then they cannot execute simultaneously in different threads. When the second thread comes to the monitor entry (the start of the synchronized method in this case), it will block until the first thread releases the monitor. The methods (instance) are of same class. So whenever a thread enters into java synchronized method or block it acquires a lock (the obj...