• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

thread

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class ThreadDemo extends Thread
{
public void run()
{
System.out.println("thread statred");
try
{
Thread.sleep(20000);
System.out.println("I am back from my sleep");
}
catch(InterruptedException e)
{
System.out.println("I got interrupted");
}
}
}
The option's are as follow's
1)Exactly 20 second's after the start method is called"I am back from my sleep" is printed"
2)we can be sure that atleast after 20 seconds elapsed, "I am back from sleep"will be printed.
3)The delay between ouytput "Thread started "and "I am back from sleep "is less or more than 20 seconds.
4)None of the above.
Th answer given is (2) and i chose 4.Please tell me the correct answer.
When a sleeping thread wake's up then it will go to the ready state.In that state it is totally up to the scheduler when it put that thread in the runnable state.Then How can a (2)option be correct?.Please tell me.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi nitin,
If u concentrate on the wording of the 2nd option which says "atleast" after 20 seconds it would print that sentence. The emphasis is on alteast that it would definitely take 20 seconds but it could take more than that also. You are absolutely right about the tansition from sleep to ready to runnable. But in any case the thread will take "ATLEAST" 20 seconds.
Hope this will help
Asif Masood
 
reply
    Bookmark Topic Watch Topic
  • New Topic