Javalin 6: a lightweight alternative to Spring Boot, now with virtual threads off by default

Javalin 6: a lightweight alternative to Spring Boot, now with virtual threads off by default

The open source Javalin project released version 6 last month, a major update to this popular lightweight web framework.

Changes in this release include making virtual threads (“Project Loom”) opt-in rather than used by default, removal of the AccessManager interface in favor of using a Context interface to check user roles, a new way of configuring the Jetty Server underlying Javalin, and a reworked plugin API.

Regarding virtual threads, enabled by default in Javalin 5 released in October 2022, the team said this was because “we wanted to make it as easy as possible to try them out.” Now that virtual threads are part of the official Java SDK, “we have decided to make them opt-in”. 

A hint as to why might be in this post. “Using Loom’s virtual threads as a default thread-pool for Javalin might not be the best idea for several reasons … [a] single synchronized block can drastically downgrade performance of the whole application,” said a team member, adding “I think we should start by not enforcing Loom as default.”

The removal of the AccessManager interface means that roles are now checked for all requests including those for static files.

Jetty is the open source web server used by Javalin and is both small and scaleable. A new set of configuration options in Javalin 6.0 gives users the ability to modify Jetty objects but not to set the Jetty server for the application to run on, since “swapping out the Jetty server could cause issues.”

The updated plugin API is “more opinionated,” the team said, which will make things “a bit harder for plugin developers” but “a lot easier for end-users.” Plugins are now represented by an abstract class which offers a standardized way of doing configuration.

Why Javalin? The most popular web application framework for Java is Spring Boot, with usage still growing according to VMWare’s report. Spring prospered by being a simpler alternative to Java Enterprise Edition; yet Javalin is simpler still. “it seems to cover everything I need from a framework in terms of URL routing and request/response handling, with minimal cruft and boilerplate,” remarked Django co-creator Simon Willison on Hacker News.  

Another plus point for Javalin is the fast performance of the Jetty server.

A key issue is developer preference over features like dependency injection. “Spring Boot’s dependency injection, auto configuration and yaml configuration system is a value proposition that I find hard to beat,” said one developer; but another commented: “I find a no-magic, code-only solution like Javalin (and Express etc) far more intuitive.”

According to its web site, Javalin is downloaded around 400,000 times a month, showing continuing interest in what is now a mature project.