我有一个JavaFX应用程序,它实例化几个Task对象.
目前,我的实现(见下文)调用行为runFactory(),它在Task对象下执行计算.与此并行,调用nextFunction().有没有办法让nextFunction() "等待"直到前一个任务完成?
我理解thread.join()等待运行的线程完成,但是使用GUI,由于事件调度线程,还有其他复杂的层.事实上,将thread.join()添加到下面的代码段末尾只会停止UI交互.
如果有任何建议如何使nextFunction等到它的先前函数,runFactory完成,我将非常感激.
谢谢,
// High-level class to run the Knuth-Morris-Pratt algorithm.
public class AlignmentFactory {
public void perform() {
KnuthMorrisPrattFactory factory = new KnuthMorrisPrattFactory();
factory.runFactory(); // nextFunction invoked w/out runFactory finishing.
// Code to run once runFactory() is complete.
nextFunction() // also invokes a Task.
...
}
}
// Implementation of Knuth-Morris-Pratt given a list of words and a sub-string.
public class …Run Code Online (Sandbox Code Playgroud)