• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread3

 
achayya matta
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Which is a possible result 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. Prints a number larger than 10000
d. Compile-time error
e. Run-time error
f. None of the above



can anyone explain me whats happening in the above code?
[ November 29, 2005: Message edited by: Mark Spritzler ]
 
Preetha Vasudevan
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it should give you a compiler error because you shuld enclose
the sleep() in a try catch block or atleast declare it even if you are not handling it
 
achayya matta
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know preetha it produces a compile time error,plz ignore that and explain me the flow of the program please
 
Lakshmanan Arunachalam
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I gone thru SUN java tutorial and Thread API, from that what my understanding is a thread is interruptible when it is in NOT RUNNABLE status.

NOT RUNNABLE status is defined as one of the following

1. In sleep
2. In wait
3. In Blocked IO/ waiting for IO
4. IN wait for other thread to complete(i.e join())

when yield method is called, still the thread is in RUNNABLE status. interrupt has no effect on a RUNNABLE thread.

I am not 100 % sure about the above theory, but I tried simulating the above conditions and worked as explained.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic