0

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.

dead programmer
  • 3,945
  • 9
  • 42
  • 71

1 Answers1

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
  • 3,958
  • 14
  • 52
  • 65