JavaFX and Concurrency

David Walend blogged about JavaFX, it’s event model, and how to handle concurrency in JavaFX applications.

All JavaFX stuff happens on the GUI thread by default. The exceptions are APIs which do threading for you, such as loading an image in the background. If you create your own (Java) Thread then you are on your own. We won’t stop you but if you touch some JavaFX structures some weird things may happen. If you need to do some non GUI work in a different thread (talk to the network, compute some calculation, etc.) then you should do it in Java and use a callback to get back into the JavaFX side. You can either use the usual Swing way, SwingUtilities.invokeLater(), or use the new FX.deferLater function. Since we have function references in JavaFX this sort of callback works quite well.

link: David Walend’s Blog: Event Based Programming in JavaFX

I think that David has hit on a really important point for Sun. Solving the programming model for concurrent applications is at the front of the line of next problems that have to be solved. I hope Sun will apply some of those mind bendingly brilliant engineers to conceiving of some language level constructs that will let you declaratively segregate your code into thread groups. I think David defined the problem well.

I’d like the power to segregate my objects into groups that I define. For example, I’d like to put the user interface of a game on one thread, the game’s logic on a second thread, and large computes and i/o operations on other threads.

Essentially, it needs to be really simple to do off graphics thread operations. As we learned from the Swing days, it is such a common source of error that it deserves to move above the api level and to a language level. I’ve gotta think through the details of this a little more, but I would appreciate any feedback you guys can give on the idea. Should this be done with an actor mechanism? Should Sun be one of the first mainstream platforms to introduce transactional memory? Could you annotate sections of code to tell the compiler that it should be off thread?


Related Posts with Thumbnails
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • DZone
  • Facebook
  • Furl
  • Google Bookmarks
  • YahooBuzz
  • YahooMyWeb

About this entry