• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
vinay singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it should be b & d ( i think)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic