InterviewSolution
| 1. |
What is synchronized method and synchronized block? Which one should be preferred? |
|
Answer» Synchronized Method: In this method, the thread acquires a lock on the object when they enter the synchronized method and releases the lock either normally or by THROWING an exception when they leave the method. No other thread can use the whole method UNLESS and until the current thread finishes its execution and release the lock. It can be used when one WANTS to lock on the entire functionality of a particular method. |
|