Common issues of J2EE system architecture

xiaoxiao2021-03-18  203

Pool management

Many resources have a commonality: supply is limited. Under normal circumstances, the reason for supply is not the lack of resources, but it is difficult to obtain. For example, we can open a database connection for each query, but this is a time consumption.

Suppose these resources (such as database connections, threads, ejb instances, etc.) are required, which will "competition" according to some application logic. Each individual resource may be used unlimited.

In WebLogic, this infrastructure can be described as:

Ÿ 包 Contains a set of resources to be managed

Ÿ 按 Provide the required resources as needed

Ÿ Refuse to provide when resources are not available

Ÿ Implement some policies to resource availability, including queuing, waiting, etc.

WebLogic thread model makes it possible to achieve access to resources well. Although developers can directly establish and manage shared pools, we do not recommend this because the container has been able to perform many similar functions. Not only that, developers must also be responsible for many implementation details (such as meticulous synchronization) to provide a resource pool for the production level.

Resource pools are often used in database connections. To facilitate discussion, assume that the database connection is established in the JDBC connection pool.

JDBC connection. The connection to the database is an expensive operation, especially during the course of operation, because each connection takes up a second setup time. Therefore, the traditional way of client processing database connection is to establish a connection between the client segment and the database when the client application is started, and the connection has been kept until the client ends. This architecture is very expensive because it is necessary to establish the same connection as the number of active clients, even if the interaction with the database is intermittent, the connection is not high, and the connection is in most cases.

In this article, we assume that resources are shared by multiple concurrent threads rather than operating systems.

Another more efficient method is to use a connection pool, which is to establish a predetermined number of database connections, and then provide it when the client needs. Since the connection has been established, it can be quickly available when the client requests. When the client is used, the connection is not canceled, but returns to the pool to use other clients.

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

New Post(0)