I have a tableview that contains a list of objects, which pull metadata from files on the harddrive.
The list can easily be 5000 items long, and has to be updated any time the hard-drive data changes. It can also be updated if the user provides an additional directory to build the dataset from. In short, the data on the tableview is liable to updated regularly.
I currently have a single thread that handles all updates. It uses a combination of a few different techniques (persistence between sessions, a FileWalker to add new data, and WatchService to watch for updates during a session). Unfortunately, this thread is not the JavaFX thread, so when I update the ObservableList
backing the TableView, I can occasionally get a ConcurrentModificationException
.
The basic shape of the background daemon thread a while ( true )
loop, because it polls the various places updates can come from, and reacts accordingly.
Platform.runLater()
does not work seem to work for this large dataset. I tried having the background thread keep a list of objects to add and remove, and then requesting that the javafx thread update the ObservableList
by reading the addMe
and removeMe
lists, but that didn't work -- the runLater()
threads stopped being called during a large read of data, and so the tableview wouldn't update for 6+ minutes until all data was done being read by the background thread. Only after that would the runLater() finally be called. I avoided calling unncessary runLater()'s by checking to see if one update request was already pending, but pruning the number of requests didn't have any impact on the result.
Is there any way to have a constantly running thread like this in the background, and have it update the dataset for a JavaFX UI? I feel like there must be some way to do this, but I can't find anything that works.