Question comes to my mind while reading about the concurrency issues in threads and dealing with it through synchronized
keyword is that,when we use the term lock
it is used for the object which contains the run
method (or the job of the thread).But why we cannot use the term lock
for the method only whose definition contains the synchronized
keyword,as this keyword means that once a thread enters the method,then this thread can only be disturbed by the JVM scheduler after the completion of the method?
i am studying from head first java and there is line written over there that the "object is locked" and the reason given is again in a questioning manner that is,"what happen if we have two synchronized method".So i am confuse here that what is the surprising thing that can happen if only the method is locked?
Please forgive me if i asked a vague question and thanks in advance.