Start here. This is the direct spoken answer to practice first.
Overview
Optimistic locking detects that another writer won; pessimistic locking reserves access before the change.
Optimistic locking normally uses a @Version field. An update includes the expected version and fails if another transaction changed the row first. It works well when conflicts are uncommon and avoids holding a database lock while a user or process thinks. Pessimistic locking requests a database lock while the transaction is active, such as a write lock on a selected row, and can be appropriate when contention is high and the operation must serialize access immediately.