Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know why I am getting this IllegalMonitorStateException?

I have an integration test that launches getty and it in turn launches a web application. The web app will span some asynchronous threads that will run initialization tasks. After that it is ready to be tested. Now because I've to wait one of those tasks to finish I thought of putting a static monitor in a shared class:

private static Object bootstrapDone = new Object();

with the following accessor methods:

public static void signalEsBoostrapCompleted(){
    synchronized (bootstrapDone){
        bootstrapDone.notifyAll();
    } 
}

public static void waitEsBoostrapCompleted() throws InterruptedException {
    synchronized (bootstrapDone){
        bootstrapDone.wait(20000);
    } 
}

If I run this in a test I get: Exception in thread "Thread-11" java.lang.IllegalMonitorStateException at java.lang.Object.notifyAll(Native Method)

from the line where the notifyAll is. I have no idea why this is happening. Can anyone help?

like image 531
gotch4 Avatar asked Nov 02 '22 12:11

gotch4


1 Answers

The only obvious way I can think of that is possible is: Something is changing the value of bootstrapDone on another thread, between the call to synchronized(bootstrapDone) and the call bootstrapDone.notifyAll().

Make bootstrapDone final and whatever can no longer be compiled is likely to be the culprit.

like image 188
Tim Boudreau Avatar answered Nov 15 '22 04:11

Tim Boudreau