File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explanation For A Thread Analogy

 
Nuwan Arambage
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,

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.


Thanks & Regards,
Nuwan Arambage


 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Threads are always more about understanding than coding...! I have only one article for you , but this is not directly for monitoring of object, instead its about

difference between WAITING and YIELDING Part 1.
difference between WAITING and YIELDING Part 2

I hope this would help for you.
 
Sergey Babkin
author
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Thanks
Javin
 
Nuwan Arambage
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah , conceptually it's dude. I got you point clearly thanks for you guidance.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic