Explain the difference between optimistic and pessimistic locking, and how you would apply them in a high-concurrency transaction environment.