Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization and wait method  RSS feed

 
d jones
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a few things I want to clarify about synchronization and threads:

1. If a method in an object is synchronized. My understanding is that only one thread can access this method for a particular instance of the object. However, a different thread can also access the same synchronized method in a DIFFERNT INSTANCE of the same object.
Is this correct? I am pretty sure it is since locks are at the object instance level and both instances of the same object would have separate locks. Just want to make sure though.

2.Is there any way to check if a thread is in a waiting state?

Many Thanks
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. That's correct as long as we are talking about instance (non-static) methods. For static methods, it doesn't matter if you try to call them using different instances; they're all synchronized at the class level.

2. Prior to JDK 5: No, not really. Since JDK 5 though, you can use the getState() method to find out what state the thread is in.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!