Why does this test program result in a java.lang.IllegalMonitorStateException?
public class test {
static Integer foo = new Integer(1);
public static void main(String[] args) {
synchronized(foo) {
foo++;
foo.notifyAll();
}
System.err.println("Success");
}
}
Result:
Exception...
What can cause that i get IllegalMonitorStateException in this code
synchronized(syncCount){
syncCount--;
syncCount.notify();
}
I'm little confused, since, as far as I know running thread must have monitor on object who's notify is called. It looks to me that my code can not be wrong, but somehow it is.
...
Hello. I am trying to synchronize two threads - the "Main" thread, and a runnable. I get the IllegalMonitorStateException, but I do not completelty understand what "you do not have the lock of the object" means.
Here is my code:
public class ThreadsTest {
private static ThreadsTest instance;
public volatile boolean flag = fals...