A better approach is to start a timer, and have timer poke the event thread every so often to go look at the staging area for updates.
更好的方法是启动计时器,并且使计时器不时地提醒事件线程去查看中间区域,以寻找更新。
AWT and Swing use this model, in which there is a GUI event thread, and all work that causes changes in the user interface must execute in that thread.
AWT和Swing就使用这个模型,在这个模型中有一个GUI事件线程,导致用户界面发生变化的所有工作都必须在该线程中执行。
How does the Event Thread know there are pending updates?
Event Thread如何知道存在未决的更新呢?
The second thread can interact with the Event thread by using a staging area and a timer.
第二个线程可以通过一个中间区域(staging area)和一个计时器,与Event Thread进行交互。
Then the Event Thread will take the updates, merge them into the existing data, and show the results.
然后,Event Thread将获取更新,将其与现有的数据合并,然后显示结果。
Then the Event Thread will take the updates, merge them into the existing data, and show the results.
然后,Event Thread将获取更新,将其与现有的数据合并,然后显示结果。
应用推荐