File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Green exam 2 #42 help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Green exam 2 #42 help" Watch "Marcus Green exam 2 #42 help" New topic

Marcus Green exam 2 #42 help


Joined: Jul 10, 2000
Posts: 20
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)??
Sharad Kumar Jain

Joined: Jan 17, 2006
Posts: 1
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
I agree. Here's the link:
subject: Marcus Green exam 2 #42 help
It's not a secret anymore!