How can I preload web application classes in the JVM at startup?

In our web applications, the first loading of some pages requires a small but noticeable additional time due to the loading of the class. Does anyone have smart ways to preload web application classes in the JVM at startup?


Update: we now store a bunch of (700) full class names in the db table. We read the table at startup and do Class.forName (). It works great, but I thought there might be a smarter approach. We identified 700 classes that were specified at startup using the profiler.

+3
source share
6 answers

, , , -, load-on-startup web.xml:

<servlet>
  <description>....</description>
  <display-name>....</display-name>
  <servlet-name>....</servlet-name>
  <servlet-class>....t</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

- , , , , - .

, , , JAR , , , JAR , JAR, - JCP- " " . , , .

+2

, . , ( , ). , ( , ).

, , , . . , ( , JIT ). : " ", , .

+2

.forName() - , . , , .

- URL- script , URL-.

+1

.forName . , .

Threading ( ), , , , , . , , , .

( , , ). , ( ).

, , .

+1

jsp, Jasper, JSP- .

0
source

Maybe you can try converting 700 classes to a jar file and apply some methods to preload, perhaps by putting jar in the path of the boot class (I'm not sure if it works, but just gives a hint).

0
source

Source: https://habr.com/ru/post/1705058/


All Articles