1
votes

In this book Enterprise JavaBeans 3.1 they talk about EJB objects and implementation objects. I am referring to what I read about stateless session beans:

Once an instance is in the Method-Ready Pool, it is ready to service client requests. When a client invokes a business method on an EJB object, the method calll is delegated to any available instance in the Method-Ready Pool. While the instance is executing the request, is is unavailable for use by other EJB objects. Once the instance has finished, it is immediately available to any EJB object that needs it. Stateless session instances are dedicated to an EJB object only for the duration of a single method call.

I understand how stateless session beans work but I don't get the difference between a EJB object and stateless session instances?

I thought I made a EJB when I annotate the class with @Stateless for example?

3
Your question is rather confusion... Where does it speak of "implementation"? Do you mean "instance" instead? - G_H

3 Answers

2
votes

I think it refers the EJB object as i.e. a field in your class which references to the EJB.
It's not an EJB instance - it's a proxy which gives you access to the EJB instance.

Therefore:

public class YourClass {

    @EJB
    private MyEJB myEjb;  // This is a proxy - not a concrete EJB instance
}

During the access, i.e. myEjb.doSomething() the container looks for free EJB instance on which the call will be executed. Another time you invoke myEjb.doSomething() the container might serve you another EJB instance.

Both times, you're using the same myEjb object, while invoked a method on (probably) different EJB instances.

That's how I would understand this paragraph.

0
votes

The EJB framework provides services like transactionality for your implmenetation classes and this is done by inversion of control.
When you write a session bean, you write only the business logic of the application and the EJB contatiner handles client calls and all middleware stuff. To do so it generates EJB objects augmented with the extra functionality and also containing your business logic. When you annotate your class, you tell the EJB container to treat it as a basis for EJB objects.
What the excerpt wishes to clarify that stateless session beans do not preserve their 'state' longer than one client request. (Not as stateful beans)

0
votes

I understand how stateless session beans work but I don't get the difference between a EJB object and stateless session instances?

I think your confusion is in the use of the term 'EJB Objects'

I don't think there's any special term 'EJB Objects'. Maybe you can read

While the instance is executing the request, is is unavailable for use by other EJB objects

as

While the instance is executing the request, is is unavailable for use by any other client

and this

Stateless session instances are dedicated to an EJB object only for the duration of a single method call.

as

Stateless session instances are dedicated to a client only for the duration of a single method call. A second call from the client uses an instance from the free-pool

("client" - can be a servlet, a session bean, an mdb, or a bean managed by CDI, or a POJO which does a JNDI lookup to acquire an ejb reference)