The analogy that I came across when I read a article form the internet.The article specifies that analogy for monitors in threading is similar to bathroom in a airplane.it explains that airplane is equal to object ,passengers are same as threads and bathroom is identical to monitor. doors attached to the bathroom is like locks.The story keep going like this. When passenger enter to the bathroom he locks the door. Meaning that thread acquire the lock. Other passengers won't be able to use the bathroom since bathroom's doors are locked.
What I need to know is what does monitor do and what does object lock do?. does object associates with particular lock and a monitor.
It's a bit confusing. There are two common meanings to the word "monitor". First, "monitor" is an antique word that means the same as modern "mutex" which is also the same as "lock" (noun). Note that the word "lock" can be used both as a verb and as a noun: you can lock a mutex and unlock a mutex, and lock a lock, and unlock a lock.
Second, in Apache code "monitor" means a combination of a mutex and a condition variable (which is an object that you can use for wait()/notify()). So, technically, the Java objects are monitors in this sense, since you can do both synchronized() (e.g. lock/unlock) and wait()/notify() on them.
And, I guess, third meaning of "monitor", used in this book, is the same as is commonly called "critical section".
Because of this confusion, the word "monitor" is best not to be used.
So, the airplane lavatory is a "critical section": place that normally can be occupied by only person at a time. The lock on the lavatory's door is a "mutex": a device that let's the current occupant to be undisturbed after it's locked and until it's unlocked. If other passengers want to use the lavatory, they find the door locked and queue up waiting for it to get unlocked, taking their turns.
Dude don't confuse yourself too much , in general sense monitor and lock used for same purpose to provide mutual exclusive access to a critical section code.l I found monitor word mostly in C , C++ while Lock mostly in Java.
Also in Java every object has a lock which is used to enter critical section.