[Guide] Transactions are crucial to ensuring data integrity and consistency. To fully understand transactions, you must be familiar with some basic concepts, models, and strategies. "Obfuscation of Transaction Models and transaction policies is a common error," Mark Richard said ".
Transactions are crucial to ensuring data integrity and consistency. To fully understand transactions, you must be familiar with some basic concepts, models, and strategies. "Obfuscation of Transaction Models and transaction policies is a common error," Mark Richard said ". This article talks about the three transaction models supported by the Java platform and discusses the four major transaction strategies based on these models. Some examples of using Spring framework and Enterprise JavaBeans (EJB) 3.0 are as follows, mark describes how the transaction model works and how it can serve as the cornerstone from basic transaction processing to high-speed transaction processing systems ".
The Java platform supports three transaction models:
* Local transaction model-transactions are managed by DB resources rather than application containers or frameworks. Developers manage connections rather than transactions.
* Programmatic transaction model-the developer obtains the transaction from the Transaction Manager and then needs to write the startup, commit, exception, and rollback code of the transaction.
* Declarative transaction model-the most common model, also known as container management transactions. In this model, containers manage transactions and developers Define (declare) the behaviors and parameters of transactions.
However, this support can only describe the basic information and expected behaviors of transactions, as well as the syntax and rules used. The transaction policy can solve the following problems: when to use the required or mandatory attributes, specific commands, which model to use, and how to optimize specific conditions.
Mark discussed the advantages and traps of the transaction model in a previous article.
This article describes how to use a specific model and how to use it in an appropriate way. The four policies are listed below:
* When the client sends multiple server-or model-based calls to complete a separate work order element, you must use the client orchestration transaction policy.
* When the main interface method for backend calls is coarse-grained (if you want to call it as a service), you need to use the API-layer transaction policy.
* A High-concurrency transaction policy is a variant of the preceding policy. This policy is usually used when the application cannot support long transactions (based on performance and scalability considerations ).
* High-speed transaction processing is perhaps the most extreme transaction strategy. This policy can be used if the application requires the fastest processing time (and throughput) while maintaining a certain degree of Atomicity in the processing process.