Java Reference
In-Depth Information
In addition to deciding how to access the database, you must decide how to
handle database concurrency. Let's look at why this is important as well as the
available options.
2.5 Decision 4: handling concurrency
in database transactions
Almost all enterprise applications have multiple users and background threads that
concurrently update the database. It's quite common for two database transactions
to access the same data simultaneously, which can potentially make the database
inconsistent or cause the application to misbehave. In the TransferService exam-
ple in chapter 1, two transactions could update the same bank account simulta-
neously, and one transaction could overwrite the other's changes; money could
simply disappear. Given that the modern banking system is not backed by gold, nor
even paper, but just supported by electronic systems, I'm sure you can appreciate
the importance of transaction integrity.
Most applications must handle multiple transactions concurrently accessing
the same data, which can affect the design of the business and persistence tiers.
Applications must, of course, handle concurrent access to shared data regard-
less of whether they are using lightweight frameworks or EJB s. However, unlike
EJB 2 entity beans, which required you to use vendor-specific extensions, JDO and
Hibernate directly support most of the concurrency mechanisms. What's more,
using them is either a simple configuration issue or requires only a small amount
of code.
The details of concurrency management are described in chapters 12 and 13.
In this section, you will get a brief overview of the different options for handling
concurrent updates in database transactions, which are transactions that do not
involve any user input. In the next section, I briefly describe how to handle con-
current updates in longer application-level transactions, which are transactions
that involve user input and consist of a sequence of database transactions.
2.5.1
Isolated database transactions
Sometimes you can simply rely on the database to handle concurrent access to
shared data. Databases can be configured to execute database transactions that
are, in database-speak, isolated from one another. Don't worry if you are not
familiar with this concept; it's explained in more detail in chapter 12. For now the
key thing to remember is that if the application uses fully isolated transactions,
 
 
 
 
Search WWH ::




Custom Search