No, here when Thread-1 is in static synchronized method1() it must be holding lock on class class’s objectand will release lock on class’s classobject only when it exits static synchronized method1(). So, Thread-2 will have to wait for Thread-1 to release lock on class’s classobject so that it could enter static synchronized method2().

Likewise, Thread-2 even cannot enter static synchronized method1() which is being executed by Thread-1. Thread-2 will have to wait for Thread-1 to release lock on class’s classobject so that it could enter static synchronized method1().

Program >

class MyRunnable1 implements Runnable{

@Override

publicvoid run(){

if(Thread.currentThread().getName().equals("Thread-1"))

method1();

else

method2();

}

staticsynchronizedvoid method1(){

System.out.println(Thread.currentThread().getName()+

" in static synchronized void method1() started");

try {

Thread.sleep(2000);

} catch (InterruptedException e) {

e.printStackTrace();

}

System.out.println(Thread.currentThread().getName()+

" in static synchronized void method1() ended");

}

staticsynchronizedvoid method2(){

System.out.println(Thread.currentThread().getName()+

" in static synchronized void method2() started");

try {

Thread.sleep(2000);

} catch (InterruptedException e) {

e.printStackTrace();

}

System.out.println(Thread.currentThread().getName()+

" in static synchronized void method2() ended");

}

}

/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */

publicclass MyClass {

publicstaticvoid main(String args[]) throws InterruptedException{

MyRunnable1 myRunnable1=new MyRunnable1();

Thread thread1=new Thread(myRunnable1,"Thread-1");

Thread thread2=new Thread(myRunnable1,"Thread-2");

thread1.start();

Thread.sleep(10);//Just to ensure Thread-1 starts before Thread-2

thread2.start();

}

}

/*OUTPUT

Thread-1 in static synchronized void method1() started

Thread-1 in static synchronized void method1() ended

Thread-2 in static synchronized void method2() started

Thread-2 in static synchronized void method2() ended

*/

If you note output, when Thread-1 was in static synchronized method1() it was holding lock on class class’s object. So, Thread-2 waited for Thread-1 to release lock on class’s classobject to enter static synchronized method2().