The difference between optimistic and pessimistic locking lock Java synchronization locks and synchronized the difference --lock [turn]

1. When the thread is pessimistic lock to get resources to the resource locked, and after submitting, before the release of the lock resources, other threads to use the resources.

2. When the thread is optimistic lock to get the resources, the optimistic locking, before submitting other locks can operate this resource, when there is conflict, before submitting a concurrency mechanism will be retained, submitted after a fight back, let after a re-thread access to resources, re-operation, then submit. And git upload the code, like, two threads are not direct access to the resource itself, but to get two copy version of the resource, and then modify the copy in both versions.

3. pessimistic locking and optimistic locking when the amount of concurrency is low, about the same performance, but at a time of high concurrency and optimistic locking performance far superior to pessimistic locking.

4. Our commonsynchronized pessimistic locks, lock is optimistic locking. See the difference between them in Java synchronization locks and synchronized --lock difference of [turn] ;

5. Another example of optimistic locking  https://www.cnblogs.com/darrenqiao/p/9211447.html

Guess you like

Origin www.cnblogs.com/MopHunter/p/11230897.html