Author
Thread.start()....
Vinney Shanmugam
Ranch Hand
Joined: Aug 27, 2008
Posts: 104
posted Jun 01, 2010 02:08:18
0
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: 14672
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
posted Jun 01, 2010 02:29:20
0
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: 14672
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: 19216
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
How To Ask Questions How To Answer Questions
Vinney Shanmugam
Ranch Hand
Joined: Aug 27, 2008
Posts: 104
posted Jun 01, 2010 02:40:24
0
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.
subject: Thread.start()....