When to use Stateful session bean over Stateless session bean?

First, you have to understand how the beans are created and handled on the server. For stateless session beans the server can maintain a variable amount of instances in a pool. Each time a client requests such a stateless bean (e.g. through a method) a random instance is chosen to serve that request. That means … Read more

Stateless and Stateful Enterprise Java Beans

Stateless Session Beans (SLSB) are not tied to one client and there is no guarantee for one client to get the same instance with each method invocation (some containers may create and destroy beans with each method invocation session, this is an implementation-specific decision, but instances are typically pooled – and I don’t mention clustered … Read more

How do CDI and EJB compare? interact?

It is currently indeed a bit confusing as there are now multiple component models in Java EE. They are CDI, EJB3 and JSF Managed Beans. CDI is the new kid on the block. CDI beans feature dependency injection, scoping and an event bus. CDI beans are the most flexible with respect to injection and scoping. … Read more

Where to use EJB 3.1 and CDI?

Yes, you can freely mix both CDI and EJB and achieve some great results. It sounds like you are using @WebService and @Schedule, which are good reasons for adding EJB to the mix. There’s a lot of confusion out there, so here is some general information on EJB and CDI as they relate to each … Read more

What is an EJB, and what does it do?

Why really use them? (Why not just stick to POJO?) IF you need a component that accesses the database, or accesses other connectivity/ directory resources, or is accessed from multiple clients, or is intended as a SOA service, EJBs today are usually “bigger, stronger, faster (or at least more scalable) and simpler” than POJOs. They … Read more

Should I use @EJB or @Inject

The @EJB is used to inject EJB’s only and is available for quite some time now. @Inject can inject any managed bean and is a part of the new CDI specification (since Java EE 6). In simple cases you can simply change @EJB to @Inject. In more advanced cases (e.g. when you heavily depend on … Read more

What exactly is Java EE?

(Updated Feb 2022) First of all, “Java EE” has since Sep 2019 been renamed to “Jakarta EE“, starting with version 8. Historically, there was also the term “J2EE” which covered versions 1.2 until 1.4. The term “Java EE” covered versions 5 until 8. See also Jakarta EE, History on Wikipedia. Is Jakarta EE just a … Read more