This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Oh boy !!!! Threads again. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Oh boy !!!! Threads again." Watch "Oh boy !!!! Threads again." New topic
Author

Oh boy !!!! Threads again.

sreelakshmi sarma
Ranch Hand

Joined: Mar 02, 2000
Posts: 130
Hello All,
I found this question in one of the mock exams. The question is
Which is true about threads?
a.If suspended cannot be restarted
b.Stop running,if another thread with higher priority is getting runnable.
c.Stop running, if the thread starts another thread with the same priority.
d.Stop running, if the thread creates another thread.
e.If interrupted, stop running.
f.If dead cannot be restarted.
The answer given is b,c,e,f.
I think only b&f are correct.According to my knowledge interrupt() only wakes up the waiting or sleeping thread and moves it into a ready state. Does it stop the executing thread. If the interrupt() is called on a thread which doesn't contain it's wait()or sleep() in a try & catch block will it stop the executing thread because of the thrown InterruptedException.
Thanks.
Please help me i am totally stuck at this point and i can't move forward.
Bytheway is there any excellent online tutorial available regarding threads.

Nilesh Parikh
Ranch Hand

Joined: Mar 14, 2000
Posts: 52
hi sree
you are perfectly right. The correct answers in my opinion are b) and f)
a)As suspended thread can always be restarted(though suspend method is deprecated in java2)
c)and d)The currently running thread will not stop running if it create another thread,irrespective of the priority of the thread.
e)Interrupt doesn't cause thread to stop.
f)Dead thread can not be restarted again, though we can use the methods of it.
Hope my wording is correct
Alkesh
sreelakshmi sarma
Ranch Hand

Joined: Mar 02, 2000
Posts: 130
Thanks alk.
Maha Anna i still need an explanation from you regarding interrupt(). So, interrupt() doesn't stop a running thread???
Nilesh Parikh
Ranch Hand

Joined: Mar 14, 2000
Posts: 52
hi sree,
maha anna explained regarding the interrupt() few days back, u can use the search facility at the top of this page and search for interrupt keyword.
I belive u will find lot of posts
Alkesh
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Sree,
I was out for some time. Regarding the interrupt, the statement If interrupted, stop running. is not true. We can not generalize the statement like that. What happens to the interrupted thread depends on what it was doing when interrupted. Depending upon that the end result varies. If the interrupted thread would have been in a waiting state, then an InterruptedException will be generated because of the interrupt() on this thread and the interrupted thread comes out of the waiting/blocked state to Ready State. On the other hand if it wasn't in a wait state and was executing some statements then the effect is different. So the above statement is not always true. Why I am saying 'always' is , the interrupted thread may want to respond to the interruption. It may provide a smooth way of going to dead state. But this happens only if it wants to.
You may find this discussion useful.
regds
maha anna

[This message has been edited by maha anna (edited March 21, 2000).]
sreelakshmi sarma
Ranch Hand

Joined: Mar 02, 2000
Posts: 130
Thank you very much Anna.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Oh boy !!!! Threads again.
 
Similar Threads
classes
Threads Execution
Garbage Collection and Threads
Marcus Mock exam 2 Threads
thread problem