aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Ishaan Mohan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
What can cause a thread to stop executing?
1) The program exits via a call to System.exit(0);
2) Another thread is given a higher priority
3) A call to the thread's stop method.
4) A call to the halt method of the Thread class
Answers 1,3 ( or 2 ?)
Can I answer 2 also ? As it is not true always.
dropinboy
Greenhorn

Joined: Jan 16, 2001
Posts: 8
hi there
i think if u call the yeild() method on the current lower-priorty(lower cause another thread has been given higher priority), the thread schedular will c there's a higher-priority and will probably execute the higher-priority thread moving the lower-priority thread into ready-to-run state.
Ishaan Mohan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Drophinboy,
but option 2 didn't mentioned call to yield() or result of yeild().
dropinboy
Greenhorn

Joined: Jan 16, 2001
Posts: 8
hi Ishaan
i don't think the thread scheduler checks for higher-priority threads unless the current thread yields/dies/interuppted, so just increasing another thread's priority won't stop the current thread.
Ishaan Mohan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Yes thats why I am confused. In mock exam option 2 is given in answer list.
lets wait for others views.
dropinboy
Greenhorn

Joined: Jan 16, 2001
Posts: 8
hi Ishaan
just read in a book i have, the words verbatim
"It can get moved out of the CPU by a higher-priority thread that becomes ready to execute"
Book Name:Complete Java 2 Certification(Robert,Heller,Ernest)
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Answer is 1, 2, and 3.
1 will always stop it from executing
2 can on some machines cause it to stop. Not guaranteed, but question says can cause a thread to stop
3 will stop it from executing
4 there is not halt method
Bill

PS dropinboy, I mentioned in another post about your name not meeting our guidelines. I mention it again in case you haven't looked at that other thread again. Please re-register with a more appropriate name. Check out this link for more info, www.javaranch.com/name.jsp

[This message has been edited by bill bozeman (edited February 28, 2001).]
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
dropinbuy,



Please read the JavaRanch policy on user names at http://www.javaranch.com/name.jsp, and re-register using an ID with a complete (and separate) first and last name, each with more than 1 letter.
Thanks,
Cindy


"JavaRanch, where the deer and the Certified play" - David O'Meara
denish mehta
Ranch Hand

Joined: Dec 21, 2000
Posts: 135
Hi
i think 2 is correct because even in time slicing the thread will be stopped from execution atleast for a while and in other os it will have to relinquish control any way
any comments???
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Threads