Interface ReadZone
- All Superinterfaces:
AutoCloseable
Read-only operations can not harm the integrity of the data persisted in the database, but in the presence of concurrent writes they still may suffer from inconsistent views and therefore may result in dirty reads. To completely prevent inconsistent views, even across classic transaction boundaries (!), invoke read-only database operations within a read zone. (Of course, a read zone must be "wide enough" to cope with all kinds of view inconsistencies. Explaining all kinds of view inconsistencies is beyond the scope of this description.)
Users are encouraged to use the try-with-resources statement to open and auto close a read zone:
// db of type Database or CustomDatabase, not null. try (ReadZone rz = db.openReadZone()) { ... }where the ellipsis stands for any program code, including code that repeats this usage pattern to create one or more nested read zones.
As long as at least one read zone is open (several read zones may be open in several threads at the same time) the database is blocked for any write database operation. Write database operations requesting the unit or threads wanting to execute a Kamikaze write are delayed until all read zones are closed.
Write database operations throw an exception if they are invoked within a read zone. Likewise, requesting the unit inside a read zone throws an exception. However, opening a read zone inside a unit is allowed.
- Author:
- Beat Hörmann
-
Method Summary
-
Method Details
-
close
Closes this read zone.Invoking this method has no effect if the database is read-only.
- Specified by:
close
in interfaceAutoCloseable
- Throws:
ACDPException
- If there is no open read zone in the current thread. This exception never happens if the database is read-only.
-