Java Reference
In-Depth Information
Inside a computer, the analogue to having multiple real-world bank tell-
ers is called multithreading. A thread, like a bank teller, can perform a
task independent of other threads. And just as two bank tellers can use
the same filing cabinets, threads can share access to objects.
This shared access is simultaneously one of the most useful features of
multithreading and one of its greatest pitfalls. This kind of getmodifyset
sequence has what is known as a race hazard or race condition. A race
hazard exists when two threads can potentially modify the same piece of
data in an interleaved way that can corrupt data. In the bank example,
imagine that someone walks up to a bank teller to deposit money into
an account. At almost the same time, a second customer asks another
teller to handle a deposit into the same account. Each teller
 
Search WWH ::




Custom Search