Use @Singleton, not @Stateless

Something I’ve been musing over in the background for some time. This is not revolutionary.

In almost any circumstance that I can think of, you probably want to be using @Singleton EJBs, not @Stateless EJBs.

In this day and age with these JVMs and these JITs, the object pooling mechanisms which seemed so necessary back in the EJB 1.x days seem laughable now.

In addition, if you’re careful, you can use concurrent utilities in your @Singleton as well, whereas the specification prevents you from doing so in any other bean type.

Author: Laird Nelson

Devoted husband and father; working on Helidon at the intersection of Java, Jakarta EE, architecture, Kubernetes and microservices at Oracle; open source guy; Hammond B3 player and Bainbridge Islander.