What is a Thread ? I understand it to be an instance of a class that implements Runable , and thus has a run() method , which is executed when the jvm works the thread ? Inside that run() method there will be some lines of code , let's suppose at any particular line , a synchronized method bar()
of object foo
is invoked , Now , when we say
First, it is not possible for two invocations of synchronized methods on the same object to interleave
i suppose it means another thread cannot call foo.bar()
untill the 1st thread has finished. Thus , the object being mentioned is foo
, and the invocation being mentioned is of the bar()
method ?
and then , when its said :
When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object.
it means that : If one thread is executing the bar()
method for foo
, foo
's intrinsic lock is currently owned by that particular thread , and all the other threads are waiting in blocked state for the lock held by the running thread to be made free , ie , the current thread to stop executing ?