Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Total no of loaded classes count keeps increasing

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

like image 479
Rips Avatar asked Oct 20 '22 13:10

Rips


1 Answers

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.

like image 131
sakura Avatar answered Oct 29 '22 17:10

sakura