I have a @Scheduled method that is called each 5 minutes.
The batch does a lot of calculation, it takes about 2-15 minutes to complete (there is a flag that prevents a batch to run if one is already running).
I use lot of Map
s to cache the results of the calculation. I could resume it like that. One major Map that will contain the cumulative results, and some Map/List into sub method for internal calculus.
The batch could take around 3-6 Gigs to run.. lot of data to analyse.
I think the Map/List that I used inside a method will be eligible to GC when the code exits the method right?
Should I use a WeakHashMap
or WeakReference
in my methods or call Map.clear();
before exiting the method?
I want to reduce the memory usage if possible that don't wait at the end of the batch for GC to do a cleanup.
When the batch is complete, the memory will reduce to 500megs-1G max.