aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Which are thread instance methods? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Which are thread instance methods?" Watch "Which are thread instance methods?" New topic
Author

Which are thread instance methods?

Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
1.wait()
2.sleep()
3.yeild()
4.start()
5.run()
6.notify() :roll:


Thanks<br />Dinesh
Manoj Macwan
Greenhorn

Joined: Aug 03, 2007
Posts: 24
wait() : This is Object class method
sleep() : This is static method of Thread class.
yeild() : This is static method of Thread class.
start() : This is instance method
run() : This is instance method
notify(): This is Object class method

So, I think the Answer should be start(), run(). Because only these methods are related to Thread instance.

But still, I have some doubts regarding run(), as run is called by VM.
Can run() method be considered as instance method of Thread class?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14153
    
  18

You can find the answer to this question very quickly by looking at the API documentation of class Thread to see which of those methods are in the class and if they are non-static.
Originally posted by Manoj Macwan:
But still, I have some doubts regarding run(), as run is called by VM.
Can run() method be considered as instance method of Thread class?

Class Thread has a public, non-static run() method so yes, run() is an instance method of class Thread.

This has nothing to do with "being called by the VM", whatever you mean by that. The run() method is not some kind of "magic" method that is called in any special way.
[ August 06, 2007: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1527
Originally posted by Manoj Macwan:
wait() : This is Object class method
sleep() : This is static method of Thread class.
yeild() : This is static method of Thread class.
start() : This is instance method
run() : This is instance method
notify(): This is Object class method

So, I think the Answer should be start(), run(). Because only these methods are related to Thread instance.

But still, I have some doubts regarding run(), as run is called by VM.
Can run() method be considered as instance method of Thread class?



I dont get the idea behind a method being 'thread-instance-method'. If wait and notify are not Thread's method, then even the run() methnod is not native to Thread class it is derived/inherited from Runnable interface. :roll:
[ August 06, 2007: Message edited by: Akhilesh Trivedi ]

Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637

I dont get the idea behind a method being 'thread-instance-method'.


Lets first define what is a instance method: If an instance is required to invoke an object then its called instance method , unlike static methods that do not need an instance of the class and can be invoked with the calss name. With this definition all the methods except the ones that are marked static are per Thread object that you create, Hence all those methods are Thread instance methods.
I think your question is trying to ask which of the following methods are defined/ovveridden in the Thread class and the answer to that is
start() and run().


If wait and notify are not Thread's method, : because they are not ovverriden in the Thread class, their definitions are in the Object class.

then even the run() methnod is not native to Thread class it is derived/inherited from Runnable interface. run() is only declared but not defined in Runnable interface. Interface are like contracts and any concrete class like Thread when it says "I implement Runnable" interface then it must define run() method.
Hope this clears the confusion.
Thanks
Deepak


SCJP, SCWCD, SCBCD
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Which are thread instance methods?