This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

vinay singh
Greenhorn

Joined: Nov 24, 2000
Posts: 4
Another question taken from JQuest mock exam.
1. public synchronized void someMethod() {
2. //lots of code
3. try {
4. Thread.sleep(500);
5. } catch(InterruptedException e) {
6. //do some things here.
7. }
8. //more and more code here
9. }
Select all correct answers
a. The code causes compilation error - sleep cannot be called inside synchronized methods.
b. The thread sleeps for atleast 500 milliseconds in this method if not interrupted.
c. When the thread "goes to sleep" it releases the lock on the object.
d. The "sleeping" threads always have the lock on the object.
The correct answers are c and d.
But aren't they contradictory???
Can anyone explain.
naveen sahu
Ranch Hand

Joined: Nov 15, 2000
Posts: 48
it should be b & d ( i think)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads