Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Ishaan Mohan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Drophinboy,
but option 2 didn't mentioned call to yield() or result of yeild().
 
dropinboy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes thats why I am confused. In mock exam option 2 is given in answer list.
lets wait for others views.
 
dropinboy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
denish mehta
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic