• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which instance?  RSS feed

 
Ravissant Markandey
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone, I read somewhere that-
" Threads calling non-static synchronized methods in the same class will only block each other if they are invoked using the same INSTANCE"

Now my question is, which INSTANCE we talking about here, the runnable instance that is passed to the thread object or the instance of the Thread class itself ?

Thanks
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ravissant Markandey:
Now my question is, which INSTANCE we talking about here, the runnable instance that is passed to the thread object or the instance of the Thread class itself ?


The instance of the class that is being used to call the "non-static synchronized method". So if you have...

MyClass obj = new MyClass();

which is then shared amoung multiple threads, then the instance is the object held by the "obj" reference -- assuming the method being called is a non-static method of the MyClass class.

Henry
[ October 24, 2007: Message edited by: Henry Wong ]
 
Ravissant Markandey
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!