Sometimes in order to get the maximum performance, the general database has the concurrency mechanism, but the problem is the data access conflict. To solve this problem, most databases use the data locking method. Therefore, pessimistic lock and optimistic lock is mainly used to ensure data security, processing multi-user concurrency.
Optimistic Lock: It is a pessimistic attitude to the data conflict, that is to say that the data will certainly conflict, so when the data began to read the data locked.
Pessimistic lock: think that the data generally does not cause conflict, so when the data is submitted to update the time, the data will be formally conflicting or not detected, if a conflict is found, let the user return the wrong information, let the user decide how to do.
Pessimistic locks can result in long access to the database and poor concurrency, especially for long transactions.
Optimistic locking in the reality of the use of more, manufacturers more use.
Optimistic and pessimistic locks on the "go" database