Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stateless session beans

 
vShyam Sundar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

What are the advantages of implementing the business logic in stateless session bean rather than implementing business logic with static methods in a java class.


Thanks,
Shyam
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With Stateless beans you will not worry about concurrency of dbConnections, objetcs. [=
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vShyam Sundar wrote:

What are the advantages of implementing the business logic in stateless session bean rather than implementing business logic with static methods in a java class.

You won't get any of the EJB semantics (like transactions) in a plain Java class. Furthermore, the stateless beans can have non-static fields (although the state shouldn't be relied upon between business method invocations), whereas your static methods on a plain Java class will not be able to store any object state.
 
vShyam Sundar
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your replies. Now my understanding after much surfing for the question i posted goes like this.

When we use stateless session bean, When ever a client request comes in, the EJB container creates an instance of the bean i.e., EJB container pulls out an instance of the bean from a session pool. In this way we can achieve scalability and moreover performance tends to improve with EJB thread management,security and transactions. Whereas when you use your java classes, you always need to create an instance for the class which in turn depends on the heap memory.

Lets say for example an application with stateless session bean invoked by 1000 users at a particular time will have significant performance over same 1000 users accessing an application without stateless session bean.

And last but not the least, Maintenance of business logic which happens to change often(depends on the application) will be much easier with EJB because of loose coupling between the client and bean Whereas with a normal java class this tends to be more tedious.

Correct me if i my understanding was wrong. and also add to this thread if there are other benefits of using a stateless session beans over normal java classes.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic