I receive data objects at random times at a high frequency, and need to update the JavaFX GUI with these. However, I don't want to fill the javafx event queue with a very large number of runnables (I use Platform.RunLater).
I have been thinking of how to best implement a throttling algorithm.
- Would it be best to have a separate GUIUpdater thread that check for example a blocking queue for new objects, and then sleeps for example for 30ms and then checks again, in an infinite loop? In that case, would a blocking queue be the optimal data structure? Please note I only need the latest data object and the blockingQueue is a FIFO queue and I can't seem to pick only the latest entry.
- Or - would it be better to simply just update the GUI with Platform.RunLater if nanoTime-startTime > 30ms? In that case, I don't need a separate thread to perform the Platform.RunLater-call. However - if an update is received when 30ms hasn't passed, and then no updates are received for some time, the last update will not show up in the GUI.
Any suggestions on how to design a throttling algorithm for JavaFX Platform.RunLater GUI updates in a short, efficient way?