• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronization Doubt

 
saied ims
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If two methods are synchronized in a class, only one thread can be accessing one of the two methods. In other words, once a thread acquires the lock on an object, no other thread can enter any of the synchronized methods in that class (for that object).
does that Object mean the Runnable instance

like
class D implements Runnable{
main(){

D nr =new D(); is that mean the object?

Thread r1=new Thread(nr);
Thread r2=new Thread(nr)
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It all depends where your synchronized methods are. If your Runnable class has a synchronized run() method, then the object used for locking is that referred to by variable nr in your example.
[ November 20, 2006: Message edited by: Barry Gaunt ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic