Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronized methods

 
geeta rai
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Lets say a class has two synchronized methods A() and B() and there are two threads TA and TB. Is it possible for TA to execute A() and TB to execute method B()independently at the same time? In other words, when a thread acquires the monitor of an object to execute a synchronized method, does it have the monitor for the specific method of the object or for the whole of the object?
Thanks.
 
srini v
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:

does it have the monitor for the specific method of the object or for the whole of the object?

The lock is for the whole of the object.
Also note that java threads are reentrant.
cheers
 
angelo celeste
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Geeta.
Have a look at this.
It may help.
http://www.csc.vill.edu/~mdamian/threads/javamonitors.html
-Angelo
 
srini v
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops! Java locks (not threads) are reentrant.
 
geeta rai
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Angelo, Srinivasan for your help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic