aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Stateless session beans 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 "Stateless session beans" Watch "Stateless session beans" New topic
Author

Stateless session beans

vShyam Sundar
Ranch Hand

Joined: Oct 13, 2010
Posts: 60
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

Joined: Jul 14, 2010
Posts: 754

With Stateless beans you will not worry about concurrency of dbConnections, objetcs. [=


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10102
    
165

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.

[My Blog] [JavaRanch Journal]
vShyam Sundar
Ranch Hand

Joined: Oct 13, 2010
Posts: 60
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.


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Stateless session beans