Compare different Java framework to generate native application.
Native
Static executable provides best performance on runtime because it’s compiled for a specific platform.
With Golang, it’s possible to generate a minimalist executable. This solution is perfect for architectures based on microservices or functions.
Before GraalVM (Ahead of time compilation), Java wasn’t be able to compete with GoLang or NodeJS. Deploying and running Java application on cloud platforms were not natural and easy.
With the aim of proposing Java cloud solution, community developed microframeworks.
Candidates
We have selected 4 frameworks to evaluate:
Code comparative
- Micronaut vs Quarkus
-import io.micronaut.http.annotation.Controller;
+import javax.inject.Inject;
-@Controller("/conferences")
+@Path("/conferences")
+@Produces(MediaType.APPLICATION_JSON)
public class ConferenceController {
- private final ConferenceService conferenceService;
+ @Inject
+ private ConferenceService conferenceService;
- public ConferenceController(ConferenceService conferenceService) {
- this.conferenceService = conferenceService;
- }
- @Get("/random")
- public Conference randomConf() {
+ @Path("/random")
+ @GET
+ public Conference randomConf() {
return conferenceService.randomConf();
}
}
- Quarkus vs Spring
-import io.micronaut.http.annotation.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
-@Controller("/conferences")
+@RestController
public class ConferenceController {
+ @Autowired
+ private ConferenceService conferenceService;
- private final ConferenceService conferenceService;
- public ConferenceController(ConferenceService conferenceService) {
- this.conferenceService = conferenceService;
- }
-
- @Get("/random")
- public Conference randomConf() {
+ @RequestMapping("/conferences/random")
+ public Conference randomConf() {
return conferenceService.randomConf();
}
}
There isn’t a big difference about syntaxes. Each selected has been thought to be productive and make happy developers.
Performance
Spring is a very popular technology and some frameworks propose partial compatibility with Spring annotation.
At then end, Spring compatibility is always limited and sometimes unstable. We recommend to not use them. Helidon is not yet mature and discarded.
Spring doesn’t propose native image generation. Pivotal will integrate this feature in 5.3 release.
Micronaut is interesting but it isn’t base on standard library. It’s out of running.
Quarkus is young but it was quickly adopted. It’s supported by RedHat and community and based on standard library (microprofile) and all RedHat stack (Vertx, …). In the opinion of performance, it’s currently the best choice.
Deal with Quarkus in depth!
Quarkus
Quarkus is an Supersonic Subatomic Java framework.
Quarkus rewrites library to be more efficient with AOT of GraalVM.
This method improves performance drastically.
We have migrate a standard microprofile application to Quarkus.
The new application performance is record breaking time of:
- memory footprint
- CPU
- Size
- Reactivity
Limitations
Not Supported | Limited |
---|---|
Dynamic Classloading | CDI |
Invoke Dynamic | Reflection |
Finalizer | Dymanic proxy |
Security Manager | JNI |
JVM TI, JMX, … | Static initializer |
Native Windows | |
Native debug |
Conclusion
Quarkus + Microcontainer is the future of Java for microservices or function.