When is there a state session bean, when is it in a stateless session bean?

zhaozj2021-02-11  254

When is there a state session bean, when is it in a stateless session bean?

Recently, there are many big strange strange things in the state of state. The stateless defect is often exaggerated, and its advantages are the same. Many stateless supporters blindly claim that there is no status that can bring greater scalability; and stateful supporters arguate that the entire system must be rebuilt in order to adapt. What is the real situation?

By correctly designed, there are two advantages: 1. Use stateless beans, EJB containers can be easily pooling and reusing beans, allowing a small number of beans to serve many clients. When you do the same thing with Stateful Bean, Bean's state must be passivated and activated between method calls, which may cause I / O bottlenecks. So there is an actual benefit of states that Pool and Reuse components are easy to use small overhead.

2. Because a Stateful session bean buffers a client's conversation in memory, a bean fails to cause losing your conversation. This can lead to a serious response, if you don't care about this, or you don't use an EJB product that provides status recovery. In a stateless model, request can be transparent to a different component, because any components can provide services for the client.

The biggest shortcoming disadvantage is that you need to push the customer-related data to the Stateless Bean in each method call. Most Stateless Session Beans will need to receive some information to a client, such as a bank account number for Banking Bean. This information is supplied to the Stateless Bean each time a client requests to reach because Beans cannot keep a status of a particular client.

A method of providing a customer-related data to beans is to transmit data as a parameter to a bean method. This may result in a decrease in performance, however, only the amount of data is large in the event of a large amount of data. This also blocks the network and reduces the bandwidth of other processes.

Another method for providing customer-related data for STATALESS BEAN, which is a client persistent storage data. The client does not need to pass all states in a method call, and only simply need data from the persistent Storage. The trade-OFF here is performance: Storage dialogging can get the storage I / O bottleneck, not a network I / O bottleneck.

A further method of surpassing the state is to use JNDI to store customer-related data to a directory structure. The client can wait for a while to pass to the bean one logo in which the data is positioned in the directory structure. This is similar to that stored data to the database. The relatively large difference is that the JNDI implementation can be an in-Memory implementation (and the same role as the shared properties manager, which is very familiar with COM readers). If there is a memory in memory, there is no database to meet.

When choosing between state and stateless, you should ask your business process to develop more calls, need a conversation? If so, there is a status model should be appropriate because the customer-related dialogue can become part of the BEAN state. Conversely, if your business process becomes a way to call, there is no status to make your needs.

Note If you want to use the status, and you have to build a web-based system, you may have to do this with a servlet's HttpSession object, and the Stateful Session Bean is the same. The case where the Stateful session bean is not httpsession is as follows: 1. You need a stateful object that a transaction perception. Your session bean can use sessionsynchronization to do this.

2. You have both Web-based also access to your EJB layer that is not web-based client, and you need a status.

3. You are temporarily storeing a temporary state of a business process using a stateful session bean, which occurs in a single HTTP request that involves multiple beans.

转载请注明原文地址:https://www.9cbs.com/read-5223.html

New Post(0)