• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marcus Green exam 2 #42 help

 
lstrite
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question says:
Which of the following statements about threading are true
1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable
2) You can obtain a mutually exclusive lock on any object
3) A thread can obtain a mutually exclusive lock on a method declared with the keyword synchronized
4) Thread scheduling algorithms are platform dependent
I knew that 2 & 4 are correct but it also says 3 is true. I thought locks are obtained for objects. If you put the synchronized modifier in front of a method doesn't it mean to synchronize on the class (object)??
thanks!
 
Sharad Kumar Jain
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure but this concept of thinking thread kinda helps me.
When u declare synchronized method, the method is like a door that allows only a single thread that has the lock for an object associated with the method.
When they say "thread can obtain a lock from synch. method", i think it might be refering to how the synchronized method works. Once a thread leaves the sync. method, the leaving thread gives up the lock that any thread can pick up and use to enter the same method. That way sync method effectively prevents multiple threads from entering the method.
Reading Synchronized methods section in RHE might help.
please, anyone correct me if i said something wrong
regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic