aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes marcus mock exam-----thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "marcus mock exam-----thread" Watch "marcus mock exam-----thread" New topic
Author

marcus mock exam-----thread

chao-long liao
Ranch Hand

Joined: Jul 29, 2001
Posts: 78
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 an object by calling a synchronized method of that object.
Answer are 2 and 3,but why ??
Amir Ghahrai
Ranch Hand

Joined: Jun 19, 2002
Posts: 110
Answer 1 is incorrect since you can synchronize an object or a method even without extending the Thread class or implementing the Runnable interface.
Answer 2 and 3 are true, since all java object have locks. i.e. you can synchronize any java object or method by the use of the keyword synchronized. this mutually exclusive locking mechanism comes from the fact, that only one thread at a time is able to execute a block of code that is synchronized.


Amir
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
The following thread also discusses this issue:
http://www.coderanch.com/t/238510/java-programmer-SCJP/certification/threads


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
jQuery in Action, 2nd edition
 
subject: marcus mock exam-----thread