Reputation: 1370
I have a program that does some kind of calculation on an external computer. That program sends information about its progress which is then shown in a GUI. It roughly works like this:
public void receiveData(final int step, final double errorRate)
{
Platform.runLater(new Runnable()
{
@Override
public void run()
{
stepLabel.setText(""+step);
errorLabel.setText(""+errorRate);
}
}
}
By the system output on the external computer, I can see that the program performs its calculation very fast. The GUI on the other hand shows program not fast enough. When the calculation is done, I can still see the values changing because the queue at Platform.runLater() still contains runnables with updates.
How can I fasten the changes?
What also would be a good soluation is that if the GUI does not show every single change in values if its not fast enough. I.e., if there is a Runnable in queue at Platform.runLater() for step 200, but receiveData() receives a value for 201, the value for 200 doesn't need to be shown because it already is obsolete.
Upvotes: 1
Views: 847
Reputation: 16476
You can apply throttling technique - put your messages into a queue and each 300ms choose the latest or aggregated/average value. This would avoid too many scheduled runnables and updates for the UI.
This method is present in RX* frameworks, i.e. in RxJS, but seems not yet being available in RxJava.
Upvotes: 2