In this blog post we will discuss about one of the very important java interview question What is difference between intrinsic synchronization and explicit locking using Lock?
|Intrinsic synchronization||Explicit Locking using Lock and Condition|
|It is not possible to interrupt a thread waiting to acquire a lock, or attempt to acquire a lock without being willing to wait for it forever.||It gives option for timed, polled or Interruptible locks helping to avoid probabilistic deadlock.|
|Responsibility of releasing a lock is handled by JVM even in case of exception occurs||Lock has to be released manually in a finally block once we have modified the protected state.|
|When multiple locks are acquired, they must be released in the same order, and all locks must be released in the same lexical scope in which they were acquired.||Ability to implement non-block-structured locking. Lock doesn’t have to be released in the same block of code, unlike synchronized locks.|
|Choice of fairness to the lock acquisition is not supported by Intrinsic synchronization||Offers choice of fairness to the lock acquisition when multiple threads try to acquire the shared lock setting fairness flag to true|
|Available from initial version of java||Available from JDK 1.5 onwards|
What are common multi-threading issues faced by Java Developers?
What are different states of a Thread? What does those states tell us?
What happens when wait() & notify() methods are called?
What is difference between sleep(), yield() and wait() method?
What is difference between Callable and Runnable Interface?
What will happen when an exception arises from within a synchronized code block? Will lock be retained or released?
What is difference between Executor submit() and execute() method?
That’s all about What is the difference between intrinsic synchronization and explicit locking using Lock?
If you have any feedback or suggestion please feel free to drop in below comment box.