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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With