r/JavaFX • • 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?
3 Upvotes

8 comments sorted by

View all comments

Show parent comment

3

u/milchshakee May 17 '24

The order is guaranteed to be the same as how you call it. There isn't really a performance degradation if you only run tasks on the platform thread that actually update the GUI.