I've got a Vehicle entity, with a Vehicle DTO.
I use OpenSessionInView
with Stripes.
In my Stripes action bean, i need to generate a csv containing the data for about 50000 Vehicles.
Thus, as a Stripes developer told me to do, i write the file to the outputstream in the following method:
StreamingResolution() {...}.stream(HttpServletResponse)
I have a service that take some pagination information, load a part of the vehicles and transform them into DTO's.
These dto's are returned to the view and written to the csv.
The pagination system (500 items for each page) was made to avoid having a list of 50000 DTO and have some memory problems.
But it doesn't work perfectly yet. With Jmap i saw that at the end of the csv process, there are more than 40000 vehicules loaded in heap space and not garbage collected.
With Yourkit profiler, it seems to me that these entities are still in the L1 cache of hibernate (referenced in StatefulPersistenceContext
), and since i have OpenSessionInView
, i guess the problem is that the conversation is a bit long and the cache need to be cleaned...
I just wonder how to do that in an elegant way since my dao methods loading vehicles are used by a lot of services that doesn't necessary need a session clean/flush.
Someone know i could do? I guess i can make a method in the DAO/Service to clear the session but it's not very elegant...
This is a pretty big project and i made a very simple description of it. Please don't tell me to not use opensessioninview or something like that, it's not my decision... ;)