I'm meeting the dreadful PermGen:Out of memory error when deploying a web-app on TomCat. I have tried many possible solutions, but they don't work out(sometimes it works, usually it doesn't). I wonder if my config in "BuildConfig.groovy" take effect:
grails.tomcat.jvmArgs = ["-Xmx1024m", "-XX:MaxPermSize=1024m"]
Does anyone know someway to view the MaxPermSize actually applied by the JVM?
You can use JVisualVM in the JDK/bin directory to monitor everything about a java process.
In direct answer to your question, java.lang.management.ManagementFactory has method to get information on all of the memory pools used by java, including the PermGen space and other non-heap memory pools:
List<MemoryPoolMXBean> memoryPoolMXBeans = java.lang.management.ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean bean : memoryPoolMXBeans) {
//Iterate over pools here
}
There's a couple of utilities that come in the jsdk i believe - try jstat -gcpermcapacity. Another trick that can sometimes be helpful is ps -fwwwC java (assuming you are running this on a linux box)
来源:https://stackoverflow.com/questions/5176748/how-can-i-view-the-maxpermsize-in-jvm