Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB Pool

 
Gagandeep-Aryan Malhotra
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gagandeep-Aryan Malhotra
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for clearing doubt. It was of great help.

Can you please elaborate more on "injecting values".

Thanks in advance.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic