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

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)
 
Consider Paul's rocket mass heater.
 
subject: Threads