I have a JavaFx program which I have created a task that downloads data from a webserver. The task is also surrounded by a service, so that the task can be recalled. What I am attempting to do is call the task/service every 30 seconds, to refresh the data. I have attempted to achieve this through inputting a 30 second sleep thread in the succeeded method in the service class. It works but also creates a delay at the start of the service. How do I call the service every 30 seconds but wont delay the service at the start of the application?
Asked
Active
Viewed 323 times
0
-
1You are looking for [ScheduledService](http://docs.oracle.com/javase/8/javafx/api/javafx/concurrent/ScheduledService.html). Check this for an example - [Simple example for 'ScheduledService' in Javafx](http://stackoverflow.com/questions/27853735/simple-example-for-scheduledservice-in-javafx) – ItachiUchiha Mar 31 '16 at 11:15
-
Thanks @ItachiUchiha for the help! I have changed our service to a ScheduledService now, and have, put in the new line of code in our main thread 'service.setPeriod(Duration.(30));' However it is coming up with an error "Cannot Find Symbol". I have also tried 'service.setPeriod(Duration.ofSeconds(30));' But that also comes up with the same error – borson89 Mar 31 '16 at 12:48
-
1I think you are looking for [Duration.seconds()](https://docs.oracle.com/javase/8/javafx/api/javafx/util/Duration.html#seconds-double-). – ItachiUchiha Mar 31 '16 at 13:40
-
Solved it using Platform.runLater() – borson89 Mar 31 '16 at 14:29