notifyAll() throws IllegalMonitorStateException

前端 未结 4 393
后悔当初
后悔当初 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:24

    From the JavaDoc of IllegalStateException

      Thrown to indicate that a thread has attempted to wait on an object's 
      monitor or to notify other threads waiting on an object's  monitor
      without owning the specified monitor. 
    

    You are trying to invoke the wait() and notifyAll() without having that object lock.

    Please try what @Jon has suggested it will work.

提交回复
热议问题