I want to have a boolean to notify some sections of the system that a specific service started.
For some strange reason I'm getting the error java.lang.IllegalMonitorStateException: object not locked by thread before notifyAll()
.
What is strange is that the notifyAll() is inside a synchronized block that takes control over the object that I call notifyAll() on.
My class starts like this:
public class MyService {
public static Boolean notifier = Boolean.valueOf(false);
@Override
public void start() {
synchronized (MyService.notifier) {
MyService.notifier = Boolean.valueOf(true);
MyService.notifier.notifyAll();
}
}
@Override
public void stop() {
synchronized (MyService.notifier) {
MyService.notifier = Boolean.valueOf(false);
MyService.notifier.notifyAll();
}
}
...
}
I'm working on an android application. I don't think it should affect anything, but I'm complementing the question with that comment in case that affects the way that java works.
Why am I getting the exception if the object is locked inside a synchronized block?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…