Both Servlet's HttpSession object and EJB's Stateful session bean are meant to maintain client state, so which one is a better option? let's look into the advantages and disadvantages of both the mechanisms :
Stateful session bean
Advantages :
1.It supports transaction service ,security service, life cycle management, RMI, instance cache, 2.thread safe etc. You need not write code for these services.
3.It can be used by both web based and non web based clients (like swing etc.) .
4.It can be used for multiple operations for a single http request.
Disadvantages :
1.Since it supports a number of services mentioned above it takes more time to process a request.
HttpSession object
Advantages :
1.It is a simple java object (perhaps a Hashtable) and takes very less time and resources to maintain a client state
Disadvantages:
1.It does not support the features discussed above
2.It cannot process multiple operations for a single http request.
So depending on your application's requirement you can choose the one best suited for you, if you want the bean only for client state management then HttpSession object gives better performance than Stateful session bean.

No comments:
Post a Comment