This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reg. Threads : Valiveru's exam

 
Angela Narain
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Given the code below
public class ThreadDemo extends Thread[
public void run(){
System.out.println("Thread started");
try{
Thread.sleep(20000); //20 seconds sleep
System.out.println("I am Back from my sleep");
}
catch(InterruptedException e){
System.out.println("I got Interrupted");
}
}
}
Which of the following statements are true? ( ANY ONE )
A.Exactly 20 seconds after the start method
is called "I am Back from my sleep" be printed.
B.We can be sure that atleast after 20 seconds elapsed,
"I am Back from sleep" will be printed.
C.The delay between output "Thread started" and "I am Back
from sleep" is less or more than 20 seconds.
D.None of the above.

I assume it is D
 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree , it shld be D
A) Exactly ! ? No we cant be sure about sleep time , it is at-least as given in parameter
B) dis option is Poorly-worded , at -least 20 seconds after wht ?
C) Dealy can never be less than as requested
Wht we can be sure about is that The delay between output "Thread started" and "I am Back
from sleep" will be atleast 20 seconds

------------------
Gagan (/^_^\)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic