• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Thread

 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what might cause the current thread to stop executing?
A) An interruptedException is thrown
B) The thread executes a sleep() call
C) The thread constructs a new Thread
D) A higher priority Thread becomes runnable
E) The thread executes a read() call on an InputStream
F) The current Thread call yield()
G) The current Thread calls wait()
H) The current thread calls notify()
The given answers are A) B) D) E) F) G)
I disagree with A. How this will affect the running thread?
Regarding B), what if is called with sleep(0), it will not stop isn't?
Regarding F), if there is no other thread, it will not stop executing.
Correct me folks, if i am wrong. I know this has been asked somany times and also there are a lot of versions of this question. Which might stop thread? what may stop thread? which will stop thread? etc etc. Can anyone elobarate the answer and difference between these questions
Thanks
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Thiru Thangavelu:
I disagree with A. How this will affect the running thread?


I agree. I don't think this constitues an automatic stop of the thread. A thread might terminate when it is interrupted, but that is up to the implementation of that thread. It is not true of all threads in general.


Regarding B), what if is called with sleep(0), it will not stop isn't?


In fact, calling sleep with an argument of 0 is very much like invoking the yield method. This basically states that the thread wishes to give up the processor in favor of other threads, but it can be put into the ready-to-run state immediately.


Regarding F), if there is no other thread, it will not stop executing.


Well, the thread will stop, temporarily. What will happen (this all assumes that the underlying OS honors the methods invoked by Java regarding thread management - this is not guaranteed) is that the thread will stop processing and go to the ready-to-run state. The underlying OS then chooses a thread from that state to start. As this is the only thread available, it will simply be started again. The thread does stop, however, temporarily, while this is done.
I hope that helps,
Corey
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what might cause !!!
I agree with A) B) D) E) F) G) becouse of the word "might", it might stop, all the answers are not thrue in generel, but might be, if the right thread sceduler is implemented !!!
 
Thiru Thangavelu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Corey,
That helped me a lot. I guess, I can choose the answers as
B) (yields and gets the processor immediately)
D)
E)
F)yields temporarily, even if there is no other thread
G)
Do you think the answers I selected will do? I just want to remind you that 2 of the mock exams(don't know the name exactly) selected A) as correct answer.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess is that when te exams state that the thread "throws an InterruptedException," they're referring to the situation when the exception is not handled within the thread and is thrown beyond the control of the thread. An uncaught exception would cause the thread to terminate.
Corey
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic