wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 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 "Thread" Watch "Thread" New topic
Author

Thread

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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//true
3) A thread can obtain a mutually exclusive lock on a method declared with the keyword synchronized//true
4) Thread scheduling algorithms are platform dependent//true
Can any one help me to understand why 2) also true ?
Thanx in advance.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
The reason 2 is true is because you can use the synchronized keyword to acquire a lock on any object you want:
<code><pre> synchronized (object) {
// JVM cannot enter this block
// until it acquires lock on "object"
}
// now lock has been given up again</pre></code>


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread