Java threads: wait and notify methods

后端 未结 7 1594
遥遥无期
遥遥无期 2020-12-04 00:28

I have a thread that calls the wait method and can only be awoken when the notify method called from some other class:

 class Threa         


        
7条回答
  •  天命终不由人
    2020-12-04 00:52

    You could loop and wait until the total has been computed :

    synchronized(b) {
       while (total == 0) {
           b.wait();
       }
    }
    

    You could also use a higher-level abstraction like a CountDownLatch.

提交回复
热议问题