Wait() & Sleep() Not Working As Thought

旧时模样 提交于 2019-12-02 08:48:15
Guillaume F.

You have two problems here, your understanding of wait(), and a GUI multithreading issue.

About the GUI multithreading... You will find more informations here about Platform.runLater(...):

Platform.runLater and Task in JavaFX

Now about Wait... It will pause your Thread until a Notify event is received through its monitor. To be able to call notify() you need to synchronize on the same object (the monitor).

synchronized (someObject) {
    someObject.wait();
}

/* different thread / object */
synchronized (someObject) {
    someObject.notify();
}

If you want to use Wait, you will need another Thread (a Timer?), to wakeup/notify you. Sleep should work fine in your case, as long as you use Platform.runlater(...)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!