notifyAll() throws IllegalMonitorStateException

前端 未结 4 398
后悔当初
后悔当初 2020-12-11 19:50

I am designing two threads: one has to get the name of players, and the second thread has to wait for the name being set in order to continue, but notify() all in the first

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 20:11

    It looks like your issue that you are using the lock incorectly. You synchronized block is on nameSetLock and you are calling your notifyall on your NameFetch object instance (which is the sayme a synchronized(this).

    You should do nameSetLock.wait when you want to use the lock and nameSetLock.notifyAll to notify.

提交回复
热议问题