File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread3" Watch "Thread3" New topic


achayya matta
Ranch Hand

Joined: Oct 27, 2005
Posts: 111

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

Joined: Sep 23, 2005
Posts: 33
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

Joined: Oct 27, 2005
Posts: 111
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

Joined: Nov 02, 2005
Posts: 99
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.

Regards<br />Lakshmanan<br />IBM-OOAD & UML, SCEA-I
I agree. Here's the link:
subject: Thread3
It's not a secret anymore!