• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting monitor of an object?

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am a bit confused about how synchronization keyword works regarding acquiring lock.
In my method if I do like this,



....so it means that synchronized block has the object ,on which method is called ,as monitor. Hence we can call
wait() method on that object. But if instead I use some other object as monitor then I suppose that I can't call wait() on current object
as now thread gets lock on that monitor object and not on the current object.
But what I see is that I am still able to call wait on current object while I was expecting IllegalMonitorStateException.

Where is my understanding wrong?

Manish

 
Rancher
Posts: 1044
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you call "wait()" without specifying on which object, it applies implicitly to the same "this", against which the block is synchronized.

Or did you describe the behaviour of another code snippet?
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ivan, thanks.

I was wrong in my understanding, now its clear to me.

Manish
 
reply
    Bookmark Topic Watch Topic
  • New Topic