DateAxis refreshTicksHorizontal needs synchronization of Dates generations
Opened this issue · 0 comments
There is a risk that the while loop inside method org.jfree.chart.axis.DateAxis:refreshTicksHorizontal get stuck in a very long lasting and CPU/memory consuming execution, leading to OutOfMemoryError. The reason is that the two variables tickDate and upperDate (used to choose to continue while loop or not) are generated separately.
- Lets say XYDataItem are yet added when the variable tickDate is set. The DateTickUnit unit will have type MILLISECOND, and the tickDate will be set to Date 1st January 1970.
- After this an XYDataItem is added to a series (of course in another Thread) with x value set to currentMillis (corresponding to todays date 15 Feb 2017).
- After this, the upperDate will be generated in the DateAxisValue. The upperDate is set to a Date similar to the added XYDataItems corresponding date.
- The while loop is then entered and the timespan is 1970 - 2017 with tickUnit set to Millisecond. The loop will continue until memory runs out.
I have experienced this scenario also after several XYDataItems were added (and a considerable amont of time had passed since fired XYDataItem addition). This means there are other time that this can occur except when having an empty chart and adding the first one, and in the same time as the HorizontalAxis is refreshed.
There are also others that ran into this earlier:
https://sourceforge.net/p/jfreechart/bugs/1111/
I've verified this problem exists in both version 1.0.19 and the latest 1.5.0-SNAPSHOT
Solution suggestion: synchronize the data that is the input for these Date so that one Thread only can access them at once, and then make a new method that returns both tickDate and upperDate at once.