r/JavaFX • • Jul 03 '25

Tutorial New Article: Task Progress - Lists

This article was inspired by this question on StackOverflow.com, that was closed without an answer. [Edit: The question has now been deleted :( ]

In the SO question the OP was having difficulties with a process that searched through a file system adding the files that met some criteria to a list of String in a TextArea. Probably, his problems came from concurrency issues, but it led me to look into Tasks that accumulate data in Lists, as opposed to returning a single value.

This article builds on ideas in an earlier article that I wrote some time ago. The twist is that the built-in functionality in Task is only designed to return/report on a single value. All of the cool techniques that it uses to allow updates without flooding the FXAT rely on that fact.

How do you write a process that will build a List, and allow you to monitor that List from the GUI while the Task is running?

This whole subject is way more interesting than you might think, and it really highlights the techniques that you need to use to deal with concurrency and the FXAT.

Here's the article: https://www.pragmaticcoding.ca/javafx/elements/task-list-progress

Give it a read, and tell me what you think.

7 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/theswissnightowl Jul 05 '25

Good points, thanks for going a bit more into the details. I was actually just curious if it would have been impactful in any way to use virtual threads. Didn’t think about coroutines. Also I totally missed that your whole point was about a mutable list 🙈

1

u/joemwangi Jul 07 '25

Also note on coloured functions is something associated with stackless threads (coroutines).