With the advancement of information, the system's dependence has become more and more strong, so a variety of data accumulation, data development rate is not high, so the data is not accurate and efficient use, this time we need to export data to Excel and then through the manual processing, but when the database data query out, found that the JVM memory continues to rise, know memory overflow, at first I thought the list is too large, I fixed the list to 1w, and then constantly loop to the database to fetch data, found that the problem is still there, there is no change, so the source of the problem, not the list, so continue to look for, Starting with the useless code isolation, found that the problem occurred in Hibernate, careful testing, found the memory of the continuous growth of the place is the Query.list () method, in order to improve efficiency, as much as possible to occupy memory, eventually lead to memory data leakage, so, I used the most direct method, List.clear () Set empty, found no effect, it makes me very incomprehensible, this return results directly return a reference, not the real list, at this time has been almost half a day past, the problem is still not solved, think of the previous data volume, many problems did not appear, So adjust the mentality, continue to look at the API, found that the session can solve the problem, so hurriedly try, sure enough, within a certain range of stability down, and data export time and efficiency significantly improved, excel2007 in 5 minutes to export 100W data to 1 sheet table is very easy, Problem solved, but still feel very uneasy, originally I know hibernate knowledge just a surface, a lot of usage is not very understanding, realization principle, realization way has not studied, so, to go the road is very long, want to learn to know a lot, re-pick up their passion, began to study hard
Hibernate solution that does not release memory when processing large amounts of data