java - LatchCountdown 在 Platform.runLater 任务上失败
问题描述
我想使用 JavaFX 可视化我的堆排序算法,每次交换数组中的元素后,我还交换 a 中对应的两个bars
值barChart
。该算法运行良好,但在更新 GUI 时,runnable
似乎并没有阻止下一个可运行文件的执行。
这是我的可运行代码片段:
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Await");
try {
latch.await();
} catch (InterruptedException ex) {
}
// queuing the done notification into the javafx thread
Platform.runLater(new Runnable() {
@Override
public void run() {
controller.updateChart(parentIndex, childIndex);
}
});
}
}).start();
锁存器被声明为类变量,并且没有在其他地方修改:
final CountDownLatch latch = new CountDownLatch(1);
这里是可运行的代码片段:
@Override
public void updateChart(int index1, int index2) {
Object tempObject = series.getData().get(index2);
series.getData().set(index2, series.getData().get(index1));
series.getData().set(index1, tempObject);
barChartCopy.getData().setAll(series);
}
任何想法,为什么不考虑闩锁?
解决方案
推荐阅读
- python - 在 Python 脚本中使用 HTML 电子邮件使用 for 循环显示 Python 列表
- php - 发送电子邮件按钮
- c++ - casablanca http_listener“将 url 添加到 url 组时出错”
- javascript - 如何使用javascript过滤包含输入单元格的表?
- javascript - 每 3 小时更换一次链接的最后一位数字 (x + 1)
- python - PySpark ChiSqSelector p 值和测试统计
- vba - ADODB reordset 值提取非常慢
- json - HTTP Webhook 回调 url 上的 JSON 架构验证(Azure 逻辑应用)
- proxy - 在 Git 中使用 .PAC 代理配置文件
- javascript - 在页面上平均分布表格列