1、1 外文原文 5.5. The Basics of Stateful Session Beans Stateful session beans are conversational beans because they hold conversations with clients that span multiple method invocations. Stateful session beans store conversational state within the bean. That conversational state is specific to a particula
2、r client. This chapter will teach you the basics of writing stateful session beans. Well begin at the conceptual level and quickly move into a code example illustrating session bean development. Well wrap up with a comparison of the stateful and stateless programming models 5.1 Characteristics of St
3、ateful Session Beans Lets begin with a look at the characteristics that all stateful session beans share 5.1.1 Achieving the Effect of Pooling with Stateful Beans Imagine a scenario where thousands of clients are having conversations with different stateful session beans running within a container.
4、Lets assume that the clients are typical clients and take a long time to think between method calls. Perhaps a client is far away, connecting from another country, and the network lag is high. Or perhaps the client represents a human interacting with a Java applet, and the human is deciding on the n
5、ext button to click Thousands of clients imply thousands of stateful session beans, each holding conversational state on behalf of a specific client. And, of course, our EJB container/server has only a finite amount of resources available, such as memory, database connections, and socket connections
6、. If the conversational state that the beans are holding is large, the container/server could easily run out of resources This was not a problem with stateless session beans because the container could pool only a few beans to service thousands of clients With stateful session beans, pooling is not as simple. When a client invokes a method on a bean, he or she is starting a conversation with the bean, and the conversational state stored in the bean must be available for that same clients