JOTM :: Core's transaction isolation level analysis and application
JOTM is an open source Java transaction manager, which provides a simple and powerful way to handle distributed transactions.The level of transaction isolation is used to control the characteristics of and send transactions, which can ensure that the transaction is correctly accessed and modified and shared data is correctly accessible within the same time.In JOTM :: CORE framework, developers can choose the appropriate transaction isolation level to meet the needs of the application.
JOTM :: Core framework supports the following four transaction isolation levels:
1. Read UncommittedThis isolation level may cause the dirt reading problem, that is, read unsurmitted data.
2. Read Community (Reading the Submitted content): This is the default transaction isolation level.It ensures that the transaction reads the data that has been submitted.Avoid dirty reading, but there may still be non-repeatable reading problems, that is, the data read in the same affairs is inconsistent.
3. Repeatable Read: At this level, transactions can read the same line of data multiple times and ensure that these reading results are consistent.It avoids the problem of re -reading, but it is still possible to have a Phantom Read problem, that is, different transactions return different results sets under the same query conditions.
4. Serializable: This is the highest level of transaction isolation level. It ensures the serial execution of the transaction and avoids problems such as dirty reading, non -repeated reading, and phantom reading.However, this isolation level may lead to decline in performance because it limits the parallelism of transactions in the concurrent environment.
TransactionManager tm = new TransactionManagerImpl();
// Set the transaction isolation level as Serializable
tm.setTransactionIsolation(TransactionIsolation.SERIALIZABLE);
// Submit a transaction
tm.commit();
In the above examples, first created a transaction manager object, `TM`, and then set the transaction isolation level by calling the` settransactionisOLATION method.Finally call the `Commit` method to submit the transaction.
In addition to the code configuration, you can also set the transaction isolation level by configuration file.Usually, the following code can be added to the configuration file of the application:
<bean id="transactionManager" class="org.objectweb.jotm.Current" init-method="start">
<property name="transactionTimeout" value="60" />
<property name="defaultTransactionIsolationLevel" value="SERIALIZABLE" />
</bean>
In the above configuration file, `DefaulttransactionILATIONLEVEL` is used to set the default transaction isolation level as Serializable.