Concurrency
- Concurrency can be defined as the ability of multiple processes to access or change shared data at the same time.
-
Pessimistic (悲观)concurrency:
The system behaves pessimistically and assumes that a conflict will occur.
Readers block writers and writer's block readers in a pessimistic concurrency environment. -
Optimistic (乐观)concurrency:
the system has few enough conflicting data modification operations that any single transaction is unlikely to modify data that another transaction is modifying.
Readers don’t block writers, and writers don’t block readers. Writers can and will block writers, however, which is what causes conflicts.
In either concurrency model, a conflict can occur if two processes try to modify the same data at the same time. The difference between the two models lies in whether conflicts can be avoided before they occur or can be dealt with in some manner after they occur.