Core java interview questions on Synchronization



1.What is synchronization?
Synchronization in java is the capability to control the access of multiple threads to any shared resource.allow only one thread to access the shared resource.

2.What is the purpose of synchronized block?
Synchronized block can be used to perform synchronization on any specific resource of the method.
Suppose you have 50 lines of code in your method, but you want to synchronize only 5 lines, you can use synchronized block.
If you put all the codes of the method in the synchronized block, it will work same as the synchronized method.

3.Can java object be locked down for exclusive use by a given thread?
Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it. If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.      
                                 
4.What is static synchronization?
If you make any static method as synchronized, the lock will be on the class not on object.

5.What is the difference b/w notify() and notifyAll()?

6.What is deadlock?




Related Post

Comments


©candidjava.com