Java Concurrency: CAS vs Locking

Posted by Hugo Walker on Stack Overflow See other posts from Stack Overflow or by Hugo Walker
Published on 2010-04-18T22:07:41Z Indexed on 2010/04/18 22:13 UTC
Read the original article Hit count: 538

Im currently reading the Book Java Concurrency in Practice. In the Chapter 15 they are speaking about the Nonblocking algorithms and the compare-and-swap (CAS) Method.

It is written that the CAS perform much better than the Locking Methods. I want to ask the people which already worked with both of this concepts and would like to hear when you are preferring which of these concept? Is it really so much faster?

Personally for me the usage of Locks is much clearer and easier to understand and maybe even better to maintain. (Please correct me if I am wrong). Should we really focus creating our concurrent code related on CAS than Locks to get a better performance boost or is sustainability a higher thing?

I know there is maybe not a strict rule, when to use what. But I just would like to hear some opinions, experiences with the new concept of CAS.

© Stack Overflow or respective owner

Related posts about java

Related posts about concurrency