简体   繁体   中英

Why is TRANSACTION_READ_COMMITTED the default in Java?

The transaction tutorial explains in the section Using Transactions to Preserve Data Integrity :

The default transaction isolation level depends on your DBMS. For example, for Java DB, it is TRANSACTION_READ_COMMITTED.

For my Postgresql database it is the same. But this does not seem to be the best, because only TRANSACTION_SERIALIZABLE prevents all inconsistencies:

Isolation Level             │Transactions │Dirty Reads   │Non-Repeatable Reads│Phantom Reads
=============================================================================================
TRANSACTION_NONE            │Not supported│Not applicable│Not applicable      │Not applicable
TRANSACTION_READ_COMMITTED  │Supported    │Prevented     │Allowed             │Allowed
TRANSACTION_READ_UNCOMMITTED│Supported    │Allowed       │Allowed             │Allowed
TRANSACTION_REPEATABLE_READ │Supported    │Prevented     │Prevented           │Allowed
TRANSACTION_SERIALIZABLE    │Supported    │Prevented     │Prevented           │Prevented

Why is not the best option the default?

There is an inverse relationship between transaction security and performance.
If you choose the best isolation level, you also get the worst performance.
You have to make a trade-off between the two.

See this benchmark for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM