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 mock exam-----thread 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 mock exam-----thread" Watch "marcus mock exam-----thread" New topic

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.

Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
The following thread also discusses this issue:

[Blog] [Blogroll] [My Reviews] My Linked In
I agree. Here's the link:
subject: marcus mock exam-----thread
It's not a secret anymore!