Optimistic Locking
Is based on the assumption that it is unlikely that separate users will access the same object simultaneously. The EJB does not hold a lock for the duration of the transaction, just for the small period of time the EJB interacts with the DB. If db detects a collision, the transaction rolls back. Suitable for large systems requiring significant concurrent access.
Pessimistic locking:
The EJB holds a lock for the duration of the transaction, not allowing any other updates to the data. Suitable for small scale system where concurrent access is
rare.