Skip to main content

Posts

Showing posts from February, 2021

Fixing Tomcat Slow startup

Fixing Tomcat Slow startup with custom jar files inside Tomcat/lib directory. Many a times, we come across some scenarios wherein there is a need to add certain jar files inside Tomcat/lib directory.  This case also arises when we are introducing a Servlet Filter in our web-app. And some external classes/ libraries are referred. In such scenarios, it is required that such classes are provided at Tomcat Server Startup. Mostly in the jar file. And when you add some custom libraries inside lib folder, Tomcat Server takes more time to boot than usual. This can be frustrating for some, as it is only consuming some time. But, this time consuming startup can be avoided. Tomcat provides a way to skip scanning the jars mentioned in tomcat.util.scan.StandardJarScanFilter.jarsToSkip property inside catalina.properties file. Add the custom jar that you suspect is taking more time during Tomcat startup. The Comment mentions :  # Default list of JAR files that should not be scanned using the JarScan

De-Registering JDBC Driver in SpringBoot

     Prevent Memory Leak by De-Registering JDBC Driver It is observed in SpringBoot Application that Database Connections might cause memory leaks.  Although Tomcat forcibly deregisters the JDBC drivers, it is good practice to clean up the resources created by webapps on context destruction. It will ensure memory leak prevention that Tomcat at times does not ensure. In simple words, it means if somehow, JDBC driver does not automatically deregister  when the servlet context is being destroyed, it can be done  at the container level also. Below snippet will ensure that the deregister of Drivers happen at the time of context destruction. @Bean protected ServletContextListener listener() { return new ServletContextListener() { @Override public void contextInitialized(ServletContextEvent sce) { } @Override public final void contextDestroyed(ServletContextEvent sce) { // ... First close any background tasks which may be using the DB ... // ... Then close any DB conn