Java Reference
In-Depth Information
The problem with using serialization and repeatable read isolation levels is
that they achieve isolation at the expense of system performance and scalability.
This is because the database handles concurrent access to shared data using
mechanisms such as locking, which reduces the amount of concurrency in the sys-
tem. As a result, many applications use a third isolation level called read commit-
ted to improve performance and scalability. Read committed provides even less
isolation than serializable or repeatable read because it does not prevent inconsis-
tent reads or lost updates. Applications make up for this lack of isolation by using
it in conjunction with either optimistic or pessimistic locking, which are described
later in this section.
Benefits and drawbacks
Fully isolated transactions have two main benefits:
They are simple to use.
They prevent many concurrency problems, including lost updates and
inconsistent reads.
The main drawback of fully isolated transactions is the high overhead, which can
reduce performance and scalability. Also, fully isolated transactions can fail more
frequently than less isolated transactions because of deadlocks and other concur-
rency-related issues.
When to use fully isolated transactions
An application should use fully isolated transactions when:
Read consistency is essential.
The overhead of fully isolated transactions is acceptable.
A typical application rarely needs to use fully isolated transactions. Instead, it
should use the read committed isolation level in conjunction with either optimis-
tic locking or pessimistic locking.
12.1.2
Optimistic locking
The trouble with fully isolated transactions is that they incur a significant over-
head regardless of whether concurrent updates actually occur. Concurrent
updates are usually quite rare, and so the mechanism that handles them should
ideally impose an overhead on the application only when one happens. A com-
monly used mechanism that works this way is optimistic locking. Despite its name,
optimistic locking doesn't actually lock anything. Instead, when a transaction
 
 
 
 
 
Search WWH ::




Custom Search