aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads 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 "Threads" Watch "Threads" New topic
Author

Threads

vinita Kh
Ranch Hand

Joined: Feb 19, 2002
Posts: 49
Question from Marcus Green-test-II
nebody explain why option 1 is false
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 synchronized method of an object
4) Thread scheduling algorithms are platform dependent
Gautam Sewani
Ranch Hand

Joined: Apr 19, 2002
Posts: 93
1 is false coz u can obtain a mutually exclusive lock on ANY OBJECT,by just calling one of its synchronized methods!
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Every object in Java has its own "lock." You can obtain that lock by calling a synchronized instance method on that object or by beginning a synchronized block which locks on that object.
Similarly, each class has its own "lock." You can obtain this lock by invoking a synchronized static method or by beginning a synchronized block which locks on that class.
As the class lock and the object lock are entirely separate, it is possible for one thread to be executing an instance method on an object while another thread executes a static method of the class of that object. It is, however, impossible for two or more threads to be executing more than one synchronized instance method (or block) and similarly for static methods (and blocks).
Check out the JLS, §17.13 Locks and Synchronization for more details.
I hope that helps,
Corey


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads
 
Similar Threads
Thread
MG2 #42
Marcus green's mock test
marcus mock exam-----thread
Object locks