Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how using Lock interface gives more performance over using synchronise keyword in concurrent applications design?

I was going through "Java Concurrency CookBook". In that author mentioned using Lock interface gives more performance over using synchronized keyword.Can any one tell how? Using the terms like stack-frame, ornumber of method calls. Don't mind, please help me get rid of java concurrency concepts.

like image 782
Nagappa L M Avatar asked Nov 01 '22 14:11

Nagappa L M


1 Answers

The raison d'etre for Lock and friends isn't that it is inherently faster than synchronized(), it is that it can be used in different ways that don't necessarily correspond to the lexical block structure, and also that it can offer more facilities such as read-write locks, counting semaphores, etc.

Whether a specific Lock implementation is actually faster than synchronized is a moot point and implementation-dependent. There is certainly no such claim in the Javadoc. Doug Leas's book[1] where it all started doesn't make any claim that I can see quickly stronger than 'often with better performance'.

[1]: Lea, Concurrent Programming in Java, 2nd edition, Addison Wesley 2000.

like image 153
user207421 Avatar answered Nov 08 '22 04:11

user207421