I need to test some JMX monitoring scripts I have developed, In particular I would like to verify that my monitoring of the PermGen region is working. So in order to test this I would like to be able to run a bit of code that loads a significant number of classes in order to consume PermGen.
My current plan is to write a script to generate prefix(1..n).java
compile them and then on cue run:
for( int i=1 ; i < n ; i ++){
Class.forName("com.mypackage.prefix"+i);
}
Is there a more elegant solution to achieve this?
OK, so looks like String.intern() will do the trick. Here is one implementation I found. Credits goes to Gareth as well: