您可以使用时间表来解决此问题:
Timeline fiveSecondsWonder = new Timeline( new Keyframe(Duration.seconds(5), new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("this is called every 5 seconds on UI thread"); }}));fiveSecondsWonder.setCycleCount(Timeline.INDEFINITE);fiveSecondsWonder.play();对于后台进程(对UI不起任何作用),您可以使用old good java.util.Timer:
new Timer().schedule( new TimerTask() { @Override public void run() { System.out.println("ping"); } }, 0, 5000);


