开发者

Session scoped Managed Bean passivation

I'm reading about JSF2 and Managed Beans. I've got a question related to passivation.

I've recently asked for different use cases of @Stateful EJB's, @SessionScoped and @ManagedBean here:

sessionscoped managed bean vs stateful ejb.

Now, stateful EJB's are eligible for passivation and activation which allow them to be temporarily passivated to persistent storage to decrease memory use when they are idle, I haven't seen this feature available to managedbeans. So it got me thinking that maybe I should go for @RequestScoped Managed Beans and prefer @Stateful EJB's for shopping carts etc instead. Using @Sessionscoped Managed Beans only to store minimal user information.

Is this correct? Are there some gui开发者_运维知识库delines for this?


A request scoped managed bean wouldn't work here. To access a particular stateful session bean instance, you need its stub.

If you were to use request scoped managed beans, there would be no place to store this stub and you would get a new instance with every request. This completely beats the reason for using stateful session beans in the first place.

You could however use a view scoped JSF managed bean (if the action takes place on a single page) or a conversation scoped CDI bean (if the action takes place on multiple pages). Especially with the latter you can tie the scope of your conversation to the life-time of the stateful session bean.

Do note that all of this requires at least an intermediate understanding of Java EE. If you're not careful with passivation of stateful session beans (e.g. never call an @Remove annotated method) it will gradually eat away the HDD space of your server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜