Win a copy of Head First Android this week in the Android forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Thread Question

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>Does anyone know the answer to this?
>
>Find the methods(2 methods) which when called CANNOT start a
>thread
> > > start()
> > > run()
> > > yield()
> > > wait()
> > > notify()
> > > notifyAll()
>
>Thanks
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yield() and wait() both stop a thread rather than start it.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to make your question more explicit/clear.
Though you should note that in order to bring a thread into ready state the only possible method employable is start().
The yield can only be applied if the thread is in running state.
wait(), notify... are Object methods and are useful in resource thread communication where wait pushes a thread to object monitor wait pool and notify tells the waiting thread that it can compete to acquire a thread schedule and then to compete to get object lock again.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dont waste a lot of time on questions like this. it tells you there are 2 correct answers.
they are yield() and wait().
 
Amond Adams
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Randall is right about not wasting time, though my choice would be run() and wait(). They don't start a thread either.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have to look at how the question is worded.CANNOT
since there are only 2 answers wait() and yield() are correct
actually now that i think about it it would be easy to create and start new threads from run()
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Find the methods(2 methods) which when called CANNOT start a
thread"
A thread is started only once, and only after invoking the start method. In other situations a thread becomes runnable, or starts running. Starts Running (after a wait) should not be confused with Starting a thread, just like 'thread stops running' should not be confused with thread stopping ( being dead).
I remember there are two versions of questions about thread stopping in mock exams. One implies that thread stops running, but the other (in Mughal Exam) implies thread dying off. So one should not intentionally create this kind of confusion.
Also relevant here is the fact is that a thread object is a kind of use and throw object. Once that thread has completed its run, invoking start would not result in its starting again. to run the code again, you need to create a new object and call start (only once).
 
Suren Babu
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feel the answers are run(), wait(), yield()
addon to the discussions above related to wait() and yield()
i think run() also - which CANNOT start the thread is the answer.
With the given thread in context, which is started using start() we cannot start() the same thread through run() method.. even though we can create child threads.
Any thoughts
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic