• 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

About Thread question?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which two cannot directly cause a thread to stop executing?

A.calling the yield method

B.calling the wait method on an object

C.calling the notify method on an object

D.calling the notifyAll method on an object

E.calling the start method on another thread object

Answer:A,E

I think the answer is wrong,because the method yield() cannot directly cause a thread to stop executing!
which methods can directly cause a thread to stop executing?
Thanks!!!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

When you copy a question from a mock exam or book, we ask you to quote your sources. So, please tell us where you copied the question from.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the API:

public static void yield()

Causes the currently executing thread object to temporarily pause and allow other threads to execute.



So, as far as I can see, the answer to the question should be E only.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does not ask whether it stops temperorily or permanently. So, I thonk the answer is correct.
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First to quote the source: Sun's SCJP1.5 e-Practice Exam

Even then notify doesn't cause a thread to stop.
I think the sense of the question is to ask about methods which stop an executing thread and out of those identify which directly cause the thread to stop.

As explained above notify and notifyAll don't cause a thread to stop (so no question of stopping it directly)

Now calling the wait method causes the thread to stop and wait (waiting from running)

The call to start on some thread or the call to yield doesn't mean a thread will be stopped. Its a matter chance which depends upon the current situation and thread scheduler.

As an example:
A thread is already running and start method is called on some other thread. We can't say that first thread will be stopped. It depends upon thread priority, thread scheduler etc.

Now calling the yield() method on a thread makes the thread to go to waiting state so that some other waiting thread may be given resources. But what if there is no other waiting thread?? The thread will continue to run.


Hope that makes things clear!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic