1

I have a method where one of the class is getting loaded by passing the current class name. This method is called from multiple places and multiple times.How many instances of the class is loaded into JVM. Does this impact the application performance.

Class TestClass{

public void load() throws Exception{
  Class.forName(TestClass.class.getName());
}

}
JavaUser
  • 25,542
  • 46
  • 113
  • 139
  • 2
    When TestClass.load() is called, TestClass is already loaded. The JVM loads a given class only once per class loader. – Olivier Mar 29 '20 at 12:39
  • 3
    Yes, each class loader has own [cache](https://stackoverflow.com/questions/34158114/why-is-classloaders-cache-checked-in-ascending-sequence) of loaded classes. – Šimon Kocúrek Mar 29 '20 at 12:47
  • 1
    `TestClass.class` does already evaluate to the same `Class` object as `Class.forName(TestClass.class.getName())` – Holger Mar 30 '20 at 08:23

0 Answers0