Friday, 4 September 2015

What is Lock interface in Java Concurrency API? What are it’s benefits over synchronization?

Lock interface provide more extensive locking operations than can be obtained using synchronized methods and statements. They allow more flexible structuring, may have quite different properties, and may support multiple associated Condition objects.
The advantages of a lock are
  • it’s possible to make them fair
  • it’s possible to make a thread responsive to interruption while waiting on a Lock object.
  • it’s possible to try to acquire the lock, but return immediately or after a timeout if the lock can’t be acquired
  • it’s possible to acquire and release locks in different scopes, and in different orders
Read more at Java Lock Example.

No comments:

Post a Comment