我有一个有点奇怪的问题,不幸的是它不是我可以轻松编写独立类的问题。在我的应用程序中,我有一个可单击的 TableView(在选项卡上)。单击此 TableView 中的一行会打开一个新选项卡,其中包含与新 TableView 中单击的行相关的数据。TableView 绑定到扩展 ModifiableObservableListBase 的自定义类。这允许使用滚动条根据视口的顶部和底部行从服务器请求新数据。这一切都很好。我的 ModifiableObservableListBase 子类中还有一个服务,用于改善高负载下的数据呈现。它使用 LinkedBlockingQueue 和 countDownLatch 以便仅将最近的视图更新到 UI 以防止不必要的重绘。使用以下内容:
setAll(list);
这也很有效。
到目前为止,一切都很好!
我注意到的是,当我多次打开和关闭这些选项卡(没有固定数量)时,在某些时候 TableView 将停止更新数据。从服务器请求并接收数据,但用于控制如何将数据添加到 ModifiableObservableListBase 的 Service 未能移出 SCHEDULED 状态。这意味着已创建的任务永远不会运行。我正在努力了解为什么这会正常工作 x 次然后停止工作。任何帮助都会受到欢迎,对不起,我没有复制此问题的独立应用程序。我会尝试重新创建它。
以下服务是在我的 ModifiableObservableListBase 子类的构造函数中构造的,每次将新选项卡(包括绑定到 ModifiableObservableListBase 的相应 TableView)添加到 UI 时都会构造该构造函数。
Service upDateService = new Service() {
@Override
protected Task createTask() {
//when the code fails it still calls to here.
return new Task() {
@Override
protected Object call() throws Exception {
//when the code fails it doesn't call the call() method
while (true) {
List<T> list = updateQueue.take();
updateLatch = new CountDownLatch(1);
//now put on the FX Application Thread
Platform.runLater(() -> {
if (list.size() > 0 && list.get(0) instanceof TableStructure) {
totalRowCount.set(((TableStructure) list.get(0)).getTotalDbRowCount());
}
setAll(list);
updateLatch.countDown();
});
try {
updateLatch.await(1, TimeUnit.MINUTES);
updateLatch = null;
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
};
}
};
upDateService.start();