Glassfish sometimes fails to stop when the PermGen is full, in this case asadmin stop-domain domain1
doesn't work. In Glassfish 2.1.1 it would just sit there forever; in 3.x it times out after AS_ADMIN_READTIMEOUT
. So I am now working on my Glassfish stop script that will kill/kill -9 it after a certain timeout to guarantee it gets stopped.
To fully test this I need to reproduce this PermGen full scenario. How can I deliberately fill up PermGen? I'm currently using Java 1.7.0_45 if that matters. I've written a program to fill up heap but this is a new one for me, I figured I'd turn to SO. It might be trickier (not sure) that it needs to be something (a .war?) I can deploy into GF. Any help is appreciated, thanks so much.
I have some thing for you. I don't know how to upload a jar file here so just adding files here.
Approach: ClassGenerator class creates a new class loader in a while loop and loads the same class over and over again until it run out of permgen. Now you will notice there is a list that keeps a reference of the loaded class. That is to prevent JVM from unloading those classes :).
Files Explained
The first image shows that when you run the program it run out of permgen space. Second image shows the structure of the project if you want to set it up in eclipse. I tested it within eclipse and exported it as a runnable jar file it works in both cases.
Run as a runnable jar file and it ran out of permgen.
Eclipse Project setup
ClassGenerator class
Dummy class. This can be any class. Sole purpose of this class is to get loaded large number of times. No other use. No logic gets executed from this class. Main logic is in ClassGenerator.java
Hope it helps you test your server crash.