我需要在“ serial”中执行三个可运行的实例,换句话说,一个接一个地但在同一线程中,然后获得结果。
当前我的代码是:
SendCommandTask sendLogReadCommand = new SendCommandTask(methodNameGetLog);
sendLogReadCommand.setOnSucceeded(eventLog -> {
this.LogTemp = ((List<Log>) sendLogReadCommand.getValue()).get(0);
SendCommandTask sendSpaceReadCommand = new SendCommandTask(methodNameGetSpace);
sendSpaceReadCommand.setOnSucceeded(eventSpace -> {
this.boxTemp = ((List<BoxLabellTs>) sendSpaceReadCommand.getValue()).get(0);
SendCommandTask sendAllLabellTssReadCommand = new SendCommandTask(methodNameGetAllLabellTss);
this.listLabellTssTemp = (List<BotLabellTs>) sendAllLabellTssReadCommand.getValue();
this.composeBox();
});
});
Platform.runLater(sendLogReadCommand);
有没有一种方法可以仅使用一个Platform.runLater命令来运行所有任务并获取每个任务的结果?
答案 0 :(得分:0)
找到了! this link solve my problem:
下面的代码很干净,可以正常工作!
public void updateGui() {
final KeyFrame kf1 = new KeyFrame(Duration.seconds(0), e -> doFirstStuff());
final KeyFrame kf2 = new KeyFrame(Duration.seconds(1), e -> doSecondStuff());
final KeyFrame kf3 = new KeyFrame(Duration.seconds(2), e -> doThirdStuff());
final Timeline timeline = new Timeline(kf1, kf2, kf3);
Platform.runLater(timeline::play);}
还可以用于此:
final Timeline timeline1 = new Timeline(kf1);
final Timeline timeline2 = new Timeline(kf2);
final Timeline timeline3 = new Timeline(kf3);
SequentialTransition sequence = new SequentialTransition(timeline1, timeline2, timeline3);
Platform.runLater(sequence::play);