Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 46 design patterns the problem with my rendering requests which are not thread safe by default This code will quickly and inevitably lock the JavaFX rendering thread due to its thread unsafe The important detail here is to perform the coordinate transformations off the rendering thread behavior This can be somewhat mitigated by wrapping the while loop in the thread safe Platform runLater Runnable which is commented out in the previous code Doing so improves the performance as follows Total elapsed time Total ns 497896 0 s 0 ms 497 us 896 ns Drew batch size of 56194 For a similar quantity of points total execution time has shrunk from 24 ms to less than 1 ms Dont be fooled though this reduced time is deceptive because what I have done is handed the workload to the JavaFX platform to manage and then execute at the next available rendering pass This approach takes much less time than the original approach without runLater but now I am sending a large number of Runnables to the JavaFX platform for processing This solution scales well to the 10000 point range However what if you want to add an order of magnitude and make it 100000 points Given all the coordinate transform math and other work being done the time spent in each Runnable instance is too large Further given the high frequency of data bursts there are far too many Runnable instances being sent to the JavaFX platform for processing This pattern could potentially throw cryptic rendering exceptions such as java lang InternalError Unrecognized PGCanvas token 64 when the underlying JavaFX engine cannot keep up Second Approach An alternative approach is a slight variation to the previous method This implementation seeks to do as little as possible in the blocking Platform runLater Runnable The code for this is shown toward the end of the following implementation of the drawNext_ ArrayTransforms method
You must have JavaScript enabled to view digital editions.