It's not a secret anymore!
The moose likes Threads and Synchronization and the fly likes Internal Implementation of run() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Internal Implementation of run()" Watch "Internal Implementation of run()" New topic

Internal Implementation of run()

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 561

Hi Ranchers,
I was unable to figure out the answer for the below question.Help provided will be appreciated.

We have the below method in Thread class

Assuming we have Thread t in place. we have to call run() method as t.start().
How will the JVM know that the t.start() method has to Invoke the run() method in this case.?Please clarify..

~Deepak Lal

When The Going Gets Tougher,The Tougher gets Going
Mos Jeff

Joined: Sep 15, 2010
Posts: 14
First you have to create a class that either extends Thread or implements Runnable interface. Then overwrite the run method. Once you have done this you can refer to the Java API for Thread start(). The start method creates a new thread and executes
Angel Taveras
Ranch Hand

Joined: Nov 13, 2008
Posts: 84

The default implementation of Thread.start() look for the given Runnable object on the Constructor if any. For more info check the Thread documentation,

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Have a look one here

|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

i have seen peoples saying that start will call the run method and yes that is correct but partially

main things is that.

Start will create a new thread and that thread after initializing itself call run method.

Internal implementation of run method,
Runnable is a interface so it doesnot contain implementation of run method.So any class which implements this interface must have to provide a implementation of run method.


It is class which simply implements a run method but doesnot do anything with it..
see below code

SCJP6.0,My blog Ranchers from Delhi
I agree. Here's the link:
subject: Internal Implementation of run()
jQuery in Action, 3rd edition