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.
source share