Can we use both Stateless and Stateful session beans in a J2EE application?

独自空忆成欢 提交于 2019-12-04 16:00:02
ewernli

You question is quite vague, but it seems like you basically ask for advice whether it's good to use either stateless or stateful session beans.

  • Stateless session beans (SLSB) are definitively easy to use. There is almost nothing to configure, and they are ideal to expose service.

  • Stateful session beans (SFSB) are superficially similar to SLSB. But the fact their are stateful make their programming model different, and are harder to use. For instance you will need to configure a pool size that matches your load, set the timeout parameter, and don't forget to dispose them correctly. People usually advice against it unless you know exactly why you would use them rather than another lighter approach (e.g. HttpSession, or database) and only if you have a good command of the EJB model. More info on Stateful EJBs in web app.

But SLSB and SFSB can of course be used together in an application. The technology is around since one decade so there's plenty of information available around. It's however encouraged to try to make your design as stateless as possible.

Of course. You should use stateless whenever possible (they are faster and consume less memory because they don't require serialization and de-serialization) and stateful only when needed. So it's perfectly ok to have (e.g.) 8 stateless and 2 stateful beans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!