【发布时间】:2015-12-17 12:13:36
【问题描述】:
我在我的应用程序中使用多个时间轴
Timeline timeLine1 = new Timeline(new KeyFrame(Duration.seconds(1), actionEvent -> {
System.out.println("Enter in timer for check and playcontent");
MaintainPlaybackArray.checkAndPlayContent();
}));
timeLine1.setCycleCount(Timeline.INDEFINITE);
timeLine1.play();
每秒钟播放一次
Timeline timeLine2 = new Timeline(new KeyFrame(Duration.seconds(5), actionEvent -> {
System.out.println("Enter in timer");
getSchedule();
checkSchedule();
}));
System.out.println("after timer");
timeLine2.setCycleCount(Timeline.INDEFINITE);
timeLine2.play();
每 5 秒调用一次
Timeline timeLine3 = new Timeline(new KeyFrame(Duration.seconds(10), actionEvent -> {
System.out.println("in timer");
String currentChecksum = Util.md5(getScheduleJsonArray().toJSONString());
if (currentChecksum != null && !currentChecksum.equalsIgnoreCase(checksum)) {
System.out.println("Schedule changed");
isScheduleChanged = true;
checksum = currentChecksum;
}
}));
System.out.println("after timer");
timeLine3.setCycleCount(Timeline.INDEFINITE);
timeLine3.play();
每 10 秒执行一次。
问题
当我在启动所有时间线后执行应用程序时,它无法以同步方式播放。
即: timLine1 不会执行 8 秒,然后突然一次执行 8 次。 时间轴 2 将在 8 秒后或 12 秒后两次执行任何时间。 timeLine3 将在 12 秒或 15 秒后执行。
所以,请帮助我以同步方式执行代码。 有什么可以代替 Timeline 的吗?
【问题讨论】:
-
您的时间线应该同时执行,很可能您在处理程序中使用的操作很长或依赖于网络,因此时间线卡在其中,看起来很卡。
-
@SergeyGrinev 你能给我建议一下这个吗?
标签: javafx-8