I'm writing a Java application (it is monitoring some files on disk and based on changes writes stuff to a database), but I noticed it spends considerable amount of time on garbage collection. A snippet of my logfile is below; about each minute it spends a second on garbage collection, and this is while the application shouldn't be doing very much. I launched Java with
java -Xmx1024m -Xms256m -verbose:gc -jar myApplication.jar
and the logfile is given as
19:38:15 pong
[Full GC 905059K->593250K(1013632K), 0.9315089 secs]
19:38:28 pong
...
19:39:34 pong
[Full GC 864134K->595982K(1013632K), 0.9592708 secs]
19:39:47 pong
....
19:40:36 pong
[Full GC 875598K->623414K(1013632K), 1.2895245 secs]
19:40:39 pong
I could probably switch to a better garbage collector, which doesn't pause my program, but I am more curious why it spends so much time开发者_Python百科 on collecting. edit: I only get the major garbage collections, I don't see minor collections.
What's the best way to debug this?
I suggest you use a memory profiler.
It appears you have a large amount of static memory, 600 MB. The full collections can be a result of creating a lot of objects (too much to fit in survivor space) If you use a memory profiler it should be more obvious.
Something simple you can do is to try and increase the young generation space. e.g. -ms800m -mx1200m -XX:NewSize=500m. This may change the behaviour and make profiling the application easier.
精彩评论