aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB Pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB Pool" Watch "EJB Pool" New topic
Author

EJB Pool

Gagandeep-Aryan Malhotra
Greenhorn

Joined: May 29, 2012
Posts: 4
Hi

Just curious to know why do we need to pool stateless session Bean.
Can't they be implemented like servlet only one instance per EJB getting request from multiple clients?

Thanks
Gagan
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10102
    
165

The EJB spec mandates that the access to EJBs be thread safe. This means that multiple clients cannot be accessing the same instance of the stateless bean at the same time. One way to achieve this goal is to have a single instance of the bean and "wait" till each of the client completes the access to the bean before letting the next client in. This obviously isn't practical for real applications. That's where the pool comes into picture. A certain number of bean instances will be available in the pool and whenever a client wants access to the bean, an instance can be allocated from that pool. This way multiple clients will work on different instances of the stateless bean at the same time.

[My Blog] [JavaRanch Journal]
Gagandeep-Aryan Malhotra
Greenhorn

Joined: May 29, 2012
Posts: 4
But for what reasons the specs mandates stateless session bean to be thread safe. For entity and Statefull this make sense. Stateless session bean will not have any instance variable. So the same instance can service multiple clients.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10102
    
165

Gagandeep-Aryan Malhotra wrote:For entity and Statefull this make sense. Stateless session bean will not have any instance variable. So the same instance can service multiple clients.


Stateless bean can have instance variables (for example you can have fields within a stateless bean which can have injected values). However the clients or the bean methods themselves aren't expected to assume that the values changed in one business method invocation will be available during another business method invocation of the same bean.
Gagandeep-Aryan Malhotra
Greenhorn

Joined: May 29, 2012
Posts: 4
Thanks for clearing doubt. It was of great help.

Can you please elaborate more on "injecting values".

Thanks in advance.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10102
    
165

Gagandeep-Aryan Malhotra wrote:

Can you please elaborate more on "injecting values".


Java EE5 and EJB3, support dependency injection. But anyway, that was just an example to help explain that the bean can hold state.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB Pool