java - the garbagecollector problem -


I have a DB connection, the question is, when I do "next" to get data from DB, So why does the garbage collector walk together? Due to GC, the data collected from DB is very slow, how can I solve it?

Because the garbage collector is running something (in this case, maybe DB connection stack) allocated to an object Trying to do is inadequate free memory. It is normal behavior and you can not completely stop it.

The first question is, is actually the reason for a significant recession? The absence of the minimum evidence you submitted. According to the observations, the slow questions are not evidence of a GC-related problem, it is to slow down the question of GC born alone, in fact, it can be surrounded on the other side. Poor query design can cause high levels of GC activity; See the 3 points below.

The second question is, why is it creating a noticeable recession? There are three possibilities:

  1. Just may be very small in your heap. JVM works best, and GC is the most efficient, if you can run with a large pile. If you walk with a small pile, then GC goes more often and takes proportionate more time to retrieve the copy per item. You can increase the size by using the JVM option "-Xmx" and "-Xms"; See them in the manual.

  2. Your application may have leakage of memory, over time it will not be full of the most useless (but garbageable) objects of your heap. Since the heap reaches completely, the GC keeps moving for a longer time, taking longer and longer time. Eventually, the application will die with out error. It is the right way to find out how to find and fix memory leak . Due to the "banded" solution such as increasing the heap, and using a fixed JVM option, JVM causes the exit when the garbage collects more than the given percentage.

  3. Your application can generate large numbers of objects because it receives query results from the database. If this is the case, increasing the size of the pile will help slightly. However, you really need to look at the detail of the DB questions that you are looking at, what is the way to reduce the amount of data received from the database. Can you reduce it by doing more work on the DB side? Finally, once you complete the above three possibilities, you will be able to run parallel GC only on a multi-core machine.


Comments