Thread not returning after notifyall()

前端 未结 1 822
一生所求
一生所求 2021-01-13 18:09

I am new to multithreading with Java. I\'ve done some research, read tutorials, and done tests, but I\'m stuck with this problem. Basically, I\'m setting up the skeleton of

相关标签:
1条回答
  • 2021-01-13 19:00

    The MainLoopThread instance waits on this (an instance of MainLoopThread), and the GFXUnpack instance notifies on this (an instance of GFXUnpack). So the notifier doesn't notify the waiting thread.

    The two objects must use the same object instance to wait and notify. And even better, you should use higher-level abstractions from the java.util.concurrent package, like Semaphores, CountDownLatches, etc., rather than these hard to use low-level methods.

    Moreover, wait() should always be called in a loop that checks if the condition necessary to wake up is realized and starts waiting again if it's not, due to spurious wakeups.

    0 讨论(0)
提交回复
热议问题