Choosing between HttpSession and Stateful session bean

banq發表於2002-11-18

Servlet的HttpSession 和EJB的Stateful session 都是維持客戶端狀態, 那麼哪個最好?看看下面的優缺點:

1 . Stateful session bean

Advantages :

It supports transaction service ,security service, life cycle management, RMI, instance cache, thread safe etc. You need not write code for these services.

It can be used by both web based and non web based clients (like swing etc.) .

It can be used for multiple operations for a single http request.

Disadvantages :

Since it supports a number of services mentioned above it takes more time to process a request.

2. HttpSession object

Advantages:

It is a simple java object (perhaps a Hashtable) and takes very less time and resources to maintain a client state

Disadvantages:

It does not support the features discussed above

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.

相關文章