• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

John Hunt Mock Exam: Q34

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I did the exam here: http://www.javaranch.com/maha/_Mock_Exams/JohnJuntMockExam.htm
I don't understand Q34. Why the answers are A,B,C,D?
------------------------------------------------------
Q. 34
Which methods may cause a thread to stop executing?
A.sleep();
B.stop();
C.yield();
D.wait();
E.notify();
F.notifyAll()
G.synchronized()
Select all correct answers.
---------------------------------------------------------
According to Mock Exam in Khalid's book,
Q11:Under which circumstance will a thread stop?
(a) The method waitforId() in class MediaTracker is called.
(b) The run() method that the thread is executing ends.
(3) The call to the start() method of the Thread object returns.
(d) The suspend() method is called on the Thread object.
(e) The wait() method is called on the Thread object.
The answer to Q11 is (b). As Khalid's explaination, Calls to methods suspend(), sleep() and wait() do not stop a thread. they only cause a thread to move out of its running state.
so, why in John Hunt answer,A C D are correct?
I am confused.
Thanks.

Cindy

 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is again and again a terminology problem !
Stop and stop executing are different IMO.
Q34 asks which method may cause a thread to stop executing, it doesn't mean that thhe thread will be stopped forever, it just means that the Thread will stop for some time.
So in Q34, A,B,C,D will all make the Thread stop executing until some conditions is satisfied again to make the Thread run again.
In Khalid's book, Q11, the question should be "Under which circumstance will a thread be stopped FOREVER ?"

Val
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As there is nothing guaranteed about yield() ,
then should it be the correct answer ?
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Be careful, the question says "...may cause..." and not will cause ! So yield is correct !
Val
 
reply
    Bookmark Topic Watch Topic
  • New Topic