We were doing performance testing of one of our legacy application when we found that no of classes loaded continously increasing which led to increase of the non heap memory.
Now I was looking for the rootcauses,One thing I could think of is that at several places we are using Class.forName like below:
Test a = (Test) Class.forName(className, false, Test.class.getClassLoader()).newInstance();
Can this be a reason ? If classname is same in the above code statement,does calling class.forName loads same class again and again.
Application server :Jboss 6.1 EAP
JDK :1.6.27
Since, the classloader would be same, it will not load the class again & again. The same class can be reloaded again only if you have multiple classloader loading the classes at different point of time.
Every classloader, first checks if the class its about to load is already loaded or not. If its not loaded then only it will load it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With