• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

one more question from Dan's questions

 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the question url: Dan's questions on threads
Question 17

What are the possible results of attempting to compile and run the program?
a. Prints a number that is less than 1000.
b. Prints a number between 1000 and 9999.
c. The printed number must always be greater than 10000.
d. Compiler error.
e. Run time error.
f. None of the above

I selected f. The answer given is c. Though the chances are that c may be the correct answer but isn't it possible that exactly 10000 is printed.
[ May 17, 2003: Message edited by: Anupam Sinha ]
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well at the time of writing the first post I hadn't tried out the code. Now I tried it and it infact gives 10000 as the output. I guess that it may vary from computer to computer and even vary when run different times on the same computer.
[ May 17, 2003: Message edited by: Anupam Sinha ]
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I should have said that the number will be greater than or equal to 10000.
The purpose of the question was really to point out that the InterruptedException is not thrown when the interrupt method is invoked on a thread that is not sleeping or waiting or blocking in the not-runnable state for any other reason.
I should probably mention that the real exam does not place a lot of emphasis on the interrupt method or the yield method. I try to avoid the use of the yield method but I used it in this question because the sleep method could cause the InterruptedException to be thrown.
Here's another interesting point. We all assume that the sleep method causes a thread to sleep for a period of time that is at least as great as the time specified by the argument. However, in reality, the actual behavior of the sleep method--at least on a Windows system--is a little different. Instead--on Windows--the actual sleep period can be shorter than the time specified by the argument. Has anyone seen this behavior documented anywhere? Does Sun acknowledge it?
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried this out.

Well more often than not slept for less time.
Few reasons why it may happen so
1. Your and my computer is very very fast, defies time.
2. Sun Microsystems time's and Microsoft time's are not fully compatible with each other.
3. Java is ahead of its time.
4. Its time for us to buy new computer.
Hope that helps. That Should
[ May 17, 2003: Message edited by: Anupam Sinha ]
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic