class Demo
{
void demo()
{
System.out.println(\"Inside demo of \"+Thread.currentThread().getName());
try
{
Thread.sleep(10000
The synchronization
only occurs in Thread1
. Since Thread2
does not synchronize
on d
, it is allowed to invoke demo()
while Thread1 holds the lock.
You seem to be misunderstanding the use of synchronized
. Synchronization only occurs with other threads trying to enter a synchronized block of the common object.