Can I auto restart tomcat jvm on out of memory exception

后端 未结 7 1641
北海茫月
北海茫月 2021-01-31 05:12

I know that this is not \"best practice\" but I would like to know if I can auto restart tomcat if my deployed app throws an outofmemory exception

7条回答
  •  清歌不尽
    2021-01-31 05:42

    I know this isn't what you asked, but have you tried looking through a heap dump to see where you may be leaking memory?

    Some very useful tools for tracking down memory leaks:

    jdk/bin/jmap -histo:live pid
    

    This will give you a histogram of all live objects currently in the JVM. Look for any odd object counts. You'll have to know your application pretty well to be able to determine what object counts are odd.

    jdk/bin/jmap -dump:live,file=heap.hprof pid
    

    This will dump the entire heap of the JVM identified by pid. You can then use the great Eclipse Memory Analyzer to inspect it and find out who is holding on to references of your objects. Your two biggest friends in Eclipse Memory Analyzer are the histo gram and a right click -> references -> exclude weak/soft references to see what is referencing your object.

    jconsole is of course another good tool.

提交回复
热议问题