For thread safety, we can use synchronized keyword or we can use Reentrant Lock in java. But why Architects persuade not to use synchronized keyword. I want to know how JVM treats the synchronized keyword internally as a result we may suffer performance issue. Please suggest me.
Asked
Active
Viewed 67 times
0
-
It's a coding issue concerned with scoping. Not an architectural issue in any way shape or form. – user207421 Sep 12 '15 at 10:23
-
The question is not a duplicate one, my question is not related to advantages of ReentrantLock over synchronized keyword, the question was how JVM treats synchronized keywords as a result we may suffer performance issue. Again the question what is the underlying issue with the usage of synchronized keyword in JLS. – Sambit Sep 12 '15 at 14:33
-
Your question is not a question about the Java language or its standard libraries: It is a question about some _particular implementation_ of the language and its libraries. There is nothing in the Java language spec that requires a `synchronized` block from being more or less performant than a `ReentrantLock`, and there is nothing in the spec that prevents it either. Probably the best thing for you to do is measure the performance yourself, on the platform in question. – Solomon Slow Sep 12 '15 at 17:52