1.10. Locking
Prev | Chapter 1. Kodo JDO Frequently Asked Questions | Next

## 1.10. Locking

1.10.1. What types of locking does Kodo provide?
1.10.2. Which kind of locking should I use for my application?

1.10.1. | What types of locking does Kodo provide?
| Kodo provides support for both datastore locking (which is required by the JDO specification) and optimistic locking (which is optional in the JDO specification). Datastore locking is implemented using pessimistic database operations that acquire locks on all objects that are retrieved in a JDO transaction. Optimistic locking, on the other hand, will verify that no other transaction has modified any of the objects at commit time, and throw an exception if the object has been changed. See Section 9.1, “Transaction Types”.
1.10.2. | Which kind of locking should I use for my application?
| The answer depends greatly on the type of application you are developing. The advantage of using pessimistic locking is that the application does not need to worry about any locking violations at commit time, but at the cost of potentially introducing serious locking contention into your application. The advantage of using optimisitc locking is that it can be much faster and makes more efficient use of database connections, since it does not necessarily need to hold open a single connection for the duration of a transaction. The primary disadvantage of optimistic locking is that the application must check for lock violation exceptions at commit time and take the appropriate actions upon failure (such as re-trying the operation).

Prev | Up | Next
1.9. Application servers | Home | 1.11. Transactions