java.lang.IllegalMonitorStateException: (m=null) Failed to get monitor for

See the javadoc for Object.wait.

in particular “The current thread must own this object’s monitor.” and “[throws] IllegalMonitorStateException – if the current thread is not the owner of the object’s monitor.” That is, you need to synchronize on the object you are going to call wait on.

so your code should be:

synchronized (available) {
    available.wait();
}

Leave a Comment