IllegalMonitorStateException on wait() call

后端 未结 10 1447
感动是毒
感动是毒 2020-11-22 11:37

I am using multi-threading in java for my program. I have run thread successfully but when I am using Thread.wait(), it is throwing java.lang.IllegalMonit

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 12:00

    Not sure if this will help somebody else out or not but this was the key part to fix my problem in user "Tom Hawtin - tacklin"'s answer above:

    synchronized (lock) {
        makeWakeupNeeded();
        lock.notifyAll();
    }
    

    Just the fact that the "lock" is passed as an argument in synchronized() and it is also used in "lock".notifyAll();

    Once I made it in those 2 places I got it working

提交回复
热议问题