Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 43 design patterns drawing in batches reduces thread contention long startTime System nanoTime int batchSize drawNext_ SimplePolling int batchSize drawNext_ ArrayTransforms printTotalTime startTime System out println Drew batch size of batchSize plotCount batchSize little thread spin helps it animate less than 15 ms can freeze graphics Thread sleep 25 if the set is plotted lets change the colors if plotCount setSize resetCanvas plotCount 0 System out println Reset Canvas In this code there are two custom method calls drawNext_ SimplePolling and drawNext_ ArrayTransforms These methods can use diferent approaches to process and render the data produced I will start with drawNext_ SimplePolling and then switch to drawNext_ ArrayTransforms and compare the results Each execution of this Task produces a graphical view similar to Figure 1 with each subsequent loop iteration graphically drawing over the previous iteration After each data set is rendered the fill color for the Canvas Figure 1 Sample output from the program
You must have JavaScript enabled to view digital editions.