vefeastern.blogg.se

Reduce startup time
Reduce startup time










reduce startup time reduce startup time

While Tomcat is good enough in most cases, other servlet containers can be more performant. Spring Boot comes with an embedded servlet container. This can result in ClassNotFoundException during runtime. Because Spring needs time to initialize the required beans, another disadvantage is that we can miss some errors on startup. The most significant disadvantage is that the application will serve the first request slower. However, lazy initialization has a few drawbacks.

#Reduce startup time code

An increased number of restarts with lazy initialization will enable JVM to optimize the code better. The reduction depends on the dependency graph of our application.Īlso, lazy initialization has benefits during development while using DevTools hot restart functionality. Lazy InitializationĪfter building a new jar file and starting it as in the previous example, the new startup time is slightly better: c.b.springStart.SpringStartApplication : Started SpringStartApplication in 2.95 seconds (JVM running for 3.497)ĭepending on the size of our codebase, lazy initialization can result in a significant amount of startup time reduction. We’ll use this time as a reference for future tweaks. We run our jar file with the standard java -jar command and monitor the start time of our application: c.b.springStart.SpringStartApplication : Started SpringStartApplication in 3.403 seconds (JVM running for 3.961)Īs we can see, our application starts at approximately 3.4 seconds. In pom.xml, we’ll add spring-boot-maven-plugin with configuration to pack our application in a jar file: Ĭom. We’ll use Spring Boot version 2.5.4 with Spring Web, Spring Actuator, and Spring Security as dependencies. Before we start, let’s set up a test application.












Reduce startup time