How does using the Lock interface provide more performance than using the synchronize keyword in the design of parallel applications?

I went through the "Java Concurrency CookBook". In this author, mentioned using the Lock interface, you get more performance using the synchronized . Can anyone tell how to do this? Using terms such as stack-frame, ornumber of method calls. Do not mind, please help me get rid of the concepts of java Concurrency.

+4
source share
1 answer

raison d'etre for Lock and friends is not that it is inherently faster than synchronized() , it can be used in different ways, which does not necessarily correspond to the lexical structure of the block and also that it can offer more features, such as locks reading and writing, counting semaphores, etc.

whether a particular Lock implementation is actually faster than synchronized is a moot point and depends on the implementation. There are no such claims in Javadok. The book by Doug Leas [1], where it all began, does not pretend that I can see faster than "often with better performance."

[1]: Lea, Parallel Programming in Java, Second Edition, Addison Wesley 2000.

+2
source

Source: https://habr.com/ru/post/1502542/


All Articles