my dog learned polymorphism*
The moose likes Java in General and the fly likes Thread.start().... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Thread.start()...." Watch "Thread.start()...." New topic
Author

Thread.start()....

Vinney Shanmugam
Ranch Hand

Joined: Aug 27, 2008
Posts: 104
To run a thread, we need to call start(). So run() method gets executed. But how it is accomplished?

I dont see any run() called from start() when i checked Thread.start() method implementation.

Actually, what happens when Thread.start() is executed by JVM, behind the scenes?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Guess what interface the Thread class is implementing. If you look at the start() method in the API, this is all explained.


[My Blog]
All roads lead to JavaRanch
Vinney Shanmugam
Ranch Hand

Joined: Aug 27, 2008
Posts: 104
Thread is implementing Runnable interface. But i dont understand your point here.

I did check start() API of Thread class and dont see any run() getting called in it. It calls some native methods only.

Can please explain, what are you trying to say?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You didn't look well enough

API wrote:
start()
Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Vinney Shanmugam wrote:To run a thread, we need to call start(). So run() method gets executed. But how it is accomplished?

I dont see any run() called from start() when i checked Thread.start() method implementation.

If you would have followed the called methods from Thread.start() you would have found a call to start0() which is a native method. The actual launching of the thread and calling of run() is done in native code.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Vinney Shanmugam
Ranch Hand

Joined: Aug 27, 2008
Posts: 104
I did see the comment " * Causes this thread to begin execution; the Java Virtual Machine
* calls the <code>run</code> method of this thread.
*

"

I too guessed that run() should be called from native. But can't let my hypothesis remains, without confirmation. Thanks for the reply.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread.start()....
 
Similar Threads
Question 18 - Dan's thread mock exam
Thread, start(), run() confusion
Threads...
can anybody tel me wat exactly Thread.start() will do?
Exam Lab Threading question