class Test {
public static void main(String[] args) {
System.out.println("1.. ");
synchronized (args) {
System.out.println("2..");
try {
Thread.currentThread().wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("3..");
}
}
}
I am getting IllegalMonitorStateException
monitor exception in this code. As per my understanding, because of synchronized block around args
which is string array object, current thread must have acquired the lock and with the wait method, I am release the lock.
Can someone explain me the reason behind this exception?