Chapter 4. Concurrency

Table of Contents

Which DB Handles are Free-Threaded
Locks, Blocks, and Deadlocks
Locks
Blocks
Deadlocks
The Locking Subsystem
Configuring the Locking Subsystem
Configuring Deadlock Detection
Resolving Deadlocks
Setting Transaction Priorities
Isolation
Supported Degrees of Isolation
Reading Uncommitted Data
Committed Reads
Using Snapshot Isolation
Transactional Cursors and Concurrent Applications
Using Cursors with Uncommitted Data
Read/Modify/Write
No Wait on Blocks
Reverse BTree Splits

DB offers a great deal of support for multi-threaded and multi-process applications even when transactions are not in use. Many of DB's handles are thread-safe, or can be made thread-safe by providing the appropriate flag at handle creation time, and DB provides a flexible locking subsystem for managing databases in a concurrent application. Further, DB provides a robust mechanism for detecting and responding to deadlocks. All of these concepts are explored in this chapter.

Before continuing, it is useful to define a few terms that will appear throughout this chapter:

Which DB Handles are Free-Threaded

The following describes to what extent and under what conditions individual handles are free-threaded.

  • Environment and the DPL EntityStore

    Free-threaded so long as EnvironmentConfig.setThreaded() is set to true.

  • Database and the DPL PrimaryIndex

    Free-threaded so long as the database or DPL PrimaryIndex is opened in a free-threaded environment.

  • SecondaryDatabase and DPL SecondaryIndex

    Same conditions apply as for Database and PrimaryIndex handles.

  • Cursor and the DPL EntityCursor

    Cursors are not free-threaded. However, they can be used by multiple threads of control so long as the application serializes access to the handle.

  • SecondaryCursor

    Same conditions apply as for Cursor handles.

  • Transaction

    Access must be serialized by the application across threads of control.

Note

All other classes found in the DPL (com.sleepycat.persist.*) and not mentioned above are free-threaded.

All classes found in the bind APIs (com.sleepycat.bind.*) are free-threaded.