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
  • 4,223
  • 9
  • 46
  • 77

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
  • 4,136
  • 16
  • 55
  • 66