• 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

sleep() method

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Source: www.danchisholm.net


Question:
What are the possible results of attempting to compile and run the program?

a. Prints a number greater than or equal to 0
b. The number printed must always be greater than 10000
c. This program will run for at least ten seconds
d. Compile-time error
e. Run-time error

The answer given is : a and c

I am not sure how c is correct, because if there is an interruption to the sleeping thread, an InterruptedException is thrown and the program halts. In such a case, the thread will run lesser than 10 seconds, and hence option c is not correct, right?
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rekha Srinath:
Source: www.danchisholm.net



I am not sure how c is correct, because if there is an interruption to the sleeping thread, an InterruptedException is thrown and the program halts. In such a case, the thread will run lesser than 10 seconds, and hence option c is not correct, right?


Hi Rekha,
Your reasoning is absolutely correct. The thread may be interrupted in between and the program may NOT always run for atleast 10 seconds. But if you read the question properly, it says: What are the possible results of attempting to compile and run the program?
Now this is a possibility that the program runs for full 10 seconds in the case that the thread is not interrupted.
So 'A' and 'C' are correct.
 
Rekha Srinath
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You caught it Paul :-)
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rekha & Paul,
I thing you thing too much :-) If you compile and run the program, there is no possibility to interrupt the sleep function, because you did not programme it. Believe in yourself, believe in your ability. You are The Programmer.
:-)
 
Paul Somnath
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Zdenek Pine:
Hi Rekha & Paul,
I thing you thing too much :-) If you compile and run the program, there is no possibility to interrupt the sleep function, because you did not programme it. Believe in yourself, believe in your ability. You are The Programmer.
:-)


What a funny post !!

reply
    Bookmark Topic Watch Topic
  • New Topic