Author Topic:   Thread
Alkesh Nandanwar
ranch hand
posted March 19, 2000 01:02 AM             
Which of the following statements is valid?
A.The JVM runs till the main method exits, even if there are other user threads running.
B.An InterruptedException occurs when the sleep() method is called on a thread.
C.A thread can be suspended for an indefinite duration of time.
D.A thread can be made in Java only by subclassing the Thread class.
E.The synchronize keyword can be used only in a method that is part of a class that is derived from Thread.

I think the correct answers are B) and c)
Any Suggestions?
Alkesh

Venkat Raman
greenhorn
posted March 23, 2000 04:10 PM         
I don't think B) is a good answer.

Calling wait() does not necessarily invite an InterruptedException. It is just a possibility.

Venkat.

javagirl
unregistered
posted March 23, 2000 04:24 PM           
The InterruptedException occurs when interrupt() is called on a thread. Not when sleep() is called.

Feel free to correct me.

venkatareddy tamma
greenhorn
posted March 23, 2000 04:57 PM             
hi
Calling wait() does not necessarily invite an InterruptedException. It is just a possibility.this possibility is not present in sleep() method.so B is wrong.and you see fourth ie D is also possible answer.

Venkat.[/B][/QUOTE]

------------------

javagirl
unregistered
posted March 23, 2000 05:51 PM           
Can anybody explain option "B". I think when sleep() is called on a currently running thread it goes to sleep. In order to wake up that thread another thread invokes interrupt() on that sleeping thread. Then it will throw InterruptedException .So,my conclusion is interrupt() triggers InterruptedException.So,every time thread goes to sleep it may throw InterruptedException if interrupt() is invoked on that. But it will not throw an Exception if it is not interrupted right?

Jim Yingst
sheriff
posted March 23, 2000 06:54 PM             
Right, javagirl. B is false.

Venkatareddy- both wait() and sleep() have the possibility of an InterruptedException. That's why the API says "throws InterruptedException" for each of these methods. However we all agree these methods do not cause the InterruptedException, so B is false.

D is false also, as shown:

    Thread t = new Thread(new Runnable({
public void run() {
System.out.println("See?");
}
});
t.start();

maha anna
bartender
posted March 24, 2000 12:53 AM             
Jim,
I think there is a small syntax error. Please correct it.
Thread t = new Thread( new Runnable() {
public void run() {}
}

);
regds
maha anna

Jim Yingst
sheriff
posted March 24, 2000 10:57 AM             
Errr... I meant to do that. Yeah. It was a test, to see who was paying attention. Yeah, that's it.


maha anna
bartender
posted March 24, 2000 10:59 AM             
Oh really?. I see.
regds
maha anna

|