ClassLoader & memory leaks: a Java love story
We’ve been experiencing very strange memory leak in our Java application servers at work: when deploying new version of a micro service, the JVM process was running out of memory and consequently crash leading to service outage.
After a bit of research, it looked like that these kind of errors were very common with this application server, especially when deploying application without restarting the server from time to time. The common fix was to restart the JVM process before putting in production, preventing any out of memory (but not the memory leak).
Using CDI 2.0 in a Java SE application
CDI (Context & Dependency Injection) is a Java API released with JEE6 that enable dependency injection. Prior to may 2017 it was only available on JEE platform, but fortunately it has changed.
CDI 2.0 (released in may 2017) add a new API to create a dependency injection container on a Java SE application. And the integration is easy. Here is how to do it:
NB: This project was written in Java 11 with maven as dependency management.