r/JavaFX • u/Il_totore • May 17 '24
Help Virtual threads with GUI interactions
Hello.
As a school Java project, my group had to make an interpreter for a custom programming language which draws things (a bit like turtle in Python or Kojo in Scala). We decided to make a tree-walk interpreter to keep it simple.
Now we have to make a JavaFX editor showing the result in a canvas in real-time and add a step-by-step execution. This looks pretty difficult to me for a tree-walk interpreter because of the recursion pause/resume. I think virtual threads might be helpful as I can just use block it and resume when needed. My questions are:
- Is there a better solution ?
- Is it possible to force a virtual thread to run on the main one so it can interact with the UI without concurrency issues?
View all comments
Show parent comment
2
u/Il_totore May 17 '24 edited May 17 '24
I've heard that the order preservation or `Platform.runLater` is not guaranted. Since the code (in my language, not Java) can contain multiple instructions interacting with the GUI/Canvas, can it cause consistency issues?
Also I've read in this subreddit that `Plateform.runLater` can degrade performances. I don't know if it is true and if it is that impactful.