Explain the difference between optimistic and pessimistic locking in a high-concurrency database environment.