In the component-base and n-tier currents, stateless (stateless) objects play an important role. The stateless object is the product of two technology combinations of OO and transaction service. OO Technology emphasizes elasticity (felxibility), reusability (reusability) and dispersibility (distribution), Transaction Service technology emphasizes efficiency (performance) and ductility (scalability). Stateless objects are an important pillar of the combination of these two technologies.
Most traditional OO technologies focus on Stateful objects, but in today's middleware (such as EJB and Com+/mts), stateless objects are far more important than Stateful objects. Especially in the EJB architecture, stateless has a very important purpose. For example, a stateless session object does not need to hold its own state value for a long time, nor is it exclusive to a particular user (client), so that many EJB objects can share a small number of stateless objects, because they are very small in server resources and are not affiliated to specific users.
Characteristics of Stateless objects
In the case of client, care is the external behavior of the server object, and the behavior is independent of the state of the object. So the client object does not have to care about the change in the state of the object, rather than the object being really stateless. For example, the stateless limit does not mean that stateless session beans cannot have attribute variables, so these sessions beans will have their own internal state, but it is important that the client does not see these internal states.
In the internet age, the scalability of information systems (scalability) is extremely important, and the premise of high scalability is the need to effectively use the resources of the server, and the resource sharing of stateless objects greatly reduces the load on the server, so when developing the N-tier system , the application of stateless objects is one of the skills that system developers must have.
Use stateless to support trading
When the number of client numbers in an enterprise information system increases dramatically, the shared resources shared by each client will naturally become scarcer. In the face of this problem, apart from putting in more resources, it is also an important solution to make good co-ordination so as to avoid waste of resources and achieve full sharing.
Among them, the database is the most typical rare shared resources, trading is a reliable technology to coordinate this shared resource, if add stateless objects, the transaction will be more powerful-more efficient use of database connection, and can cross different databases (that is, distributed transactions).
A trade is a business transaction or an event of a different movement. Once an event occurs, an enterprise information system participates in a series of job processes (process), which leads to a series of changes in shared resources such as database data. In order to ensure that there is no interference with other transactions during the course of the process, and in order to ensure exception handling in the process of the roll (e.g., back), "transaction" becomes a tool for managing and coordinating shared resources.
In the transaction process, the database needs to provide services (ie, resources), so that the data can be moved to the database, after the completion of the release of resources for the use of Peter Trading. In the transaction services (transaction service), such as EJB systems, you must have acid (Atomic,consistency,isolation,duration) Four features to achieve these resource management functions.
Generally speaking, must obtain and the database communication pipeline (connection), can obtain the database service, but the database connection is very limited, therefore the coordination connection becomes the Management database resource center of gravity. Allowing every client to release connection as soon as possible becomes an important management task.
In the course of the transaction, will obtain the required database connection, until the end of the transaction will be released, so fully use the connection must pay attention to two points, one is the transaction of the shorter the better, the shorter the transaction will be able to quickly release the occupied connection. The second is that the exchange needs less connection the better, so there will be more sharing opportunities.
In a component-based environment, a transaction is usually performed by a group of objects, each of which may be designed and developed by different people, and each object may request connection from the database. If the number of participants in a transaction is greater, and the longer the connection time of each object, the transaction requires enough connection to complete the task.
Therefore, "let the object quickly release connection" is an important strategy to improve the efficiency of database resource utilization, stateless object is the important technology to implement this strategy.