In an interview I was asked about the difference between Lock and synchronize. Which will I should prefer. Logically I find both as same. We can achieve all the task using any of them. But not able to answer what he wants to listen.
Asked
Active
Viewed 34 times
1 Answers
0
Locking and Synchronize achieve the same thing, but synchronize is less efficient. You can read more about why synchronize is expensive in java from this answer here: Why are synchronize expensive in Java?

medium
- 4,136
- 16
- 55
- 66