Let's look at the definition of synchronized methods on the oracle documentation page.
Creating synchronized methods has two effects:
First, it is not possible for two calls of synchronized methods on the same object to alternate. When one thread executes a synchronized method for an object, all other threads that invoke synchronized methods for the same object (pause execution) until the first thread executes with the object.
Returning to your request:
synMethod() is the level of the object with the synchronized object. Two threads accessing the same synchronized method receive an object lock in a sequential manner. But two threads accessing the synchronous method of different instances (objects) are started asynchronously in the absence of a common lock.
myThread and myThread2 are two different objects => Internal locks are acquired in two different objects, and therefore you can access these methods asynchronously.
One solution: as stated in Mureinik, use a shared object to lock.
Another solution: use better concurrency constructs like ReentrantLock etc.
You will find several alternatives in the SE related question:
Avoid syncing (this) in Java?
source share